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

'!debugNeedsPaint': is not true. ERROR #10

Closed Choi-Woo-Young closed 6 months ago

Choi-Woo-Young commented 11 months ago

Hello. I'm using your package well. But When the capture() function was called, the following error pack occurred.

UI WidgetsToImage(controller: controller.pollDocImageController, child: _buildPoll()),

GetXController pollDocBytes.value = await pollDocImageController.capture() ?? Uint8List(0);

ERROR [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:flutter/src/rendering/proxy_box.dart': Failed assertion: line 3379 pos 12: '!debugNeedsPaint': is not true.

mixedteam236 commented 8 months ago

The docs for debugNeedsPaint states: Whether this render object's paint information is dirty. Wrapping controller.capture() in two addPostFrameCallback works for me:

WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
  WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
    final bytes = await controller.capture();
    setState(() {
      this.bytes = bytes;
    });
  });
});
MohamedAbd0 commented 6 months ago

I upload the new version to solve this pugs.