MohamedAbd0 / widgets_to_image

Export your widget to image with flutter
https://pub.dev/packages/widgets_to_image
MIT License
22 stars 7 forks source link

not working with ios app #14

Open dhrutimehta opened 5 months ago

dhrutimehta commented 5 months ago

error : [ERROR:flutter/lib/ui/painting/image_encoding.cc(210)] Could not convert raster image to PNG.

JaspreetSingh04012001 commented 5 months ago

Yes please look into this issue

MohamedAbd0 commented 5 months ago

can you shard the code with me?

amankachhal99 commented 4 months ago

I am also facing similar kind of issue

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Unable to find RenderRepaintBoundary

0 WidgetsToImageController2.capture. (package:aanandamfe/services/share_info/widgets_to_image_controller.dart:38:11)

1 new Future.delayed. (dart:async/future.dart:423:39)

2 Timer._createTimer. (dart:async-patch/timer_patch.dart:18:15)

3 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)

4 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)

5 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Future<Uint8List?> capture({ double pixelRatio = 6, }) async { try { return await Future.delayed(Duration.zero, () async { RenderRepaintBoundary? boundary = containerKey.currentContext?.findRenderObject() as RenderRepaintBoundary?;

    if (boundary == null) {
      throw Exception('Unable to find RenderRepaintBoundary');
    }

    final image = await boundary.toImage(pixelRatio: pixelRatio);
    final byteData = await image.toByteData(format: ui.ImageByteFormat.png);
    final pngBytes = byteData?.buffer.asUint8List();
    return pngBytes;
  });
} catch (e) {
  rethrow;
}

}

static Future shareWidgetByImage(Widget widget, String content) async { // WidgetsToImageController to access widget WidgetsToImageController2 controller = WidgetsToImageController2(); // to save image bytes of widget Uint8List? bytes; WidgetsToImage2( controller: controller, child: widget, ); // Ensure the capture is done after the widget is rendered WidgetsBinding.instance!.addPostFrameCallback((_) async { bytes = await controller.capture(); if (bytes != null) { shareImageFromBytes(bytes!, content); } else { _logger.e('Failed to capture widget as image'); } }); }