Reputation: 1
Future<ui.Image> toImage({ double pixelRatio = 1.0 }) {
assert(!debugNeedsPaint);
final OffsetLayer offsetLayer = layer! as OffsetLayer;
return offsetLayer.toImage(Offset.zero & size, pixelRatio: pixelRatio);
}
I get an error? This is the error in the console package:flutter/src/rendering/proxy_box.dart': Failed assertion: line 3379 pos 12: '!debugNeedsPaint': is not true.
I've tried various things but it doesn't work.
Upvotes: 0
Views: 287
Reputation: 11
You can try this way to do it. The problem with your code is that it is unable to re-render the Image with extension .toImage()
.
I hope this would work.
Future<void> _capturePng() {
return new Future.delayed(const Duration(milliseconds: 20), () async {
RenderRepaintBoundary boundary =
globalKey.currentContext.findRenderObject();
ui.Image image = await boundary.toImage();
ByteData byteData =
await image.toByteData(format: ui.ImageByteFormat.png);
Uint8List pngBytes = byteData.buffer.asUint8List();
print(pngBytes);
});
}
Upvotes: 1