toBlob method
Implementation
Future<Uint8List> toBlob({ double? devicePixelRatio }) {
Completer<Uint8List> completer = Completer();
forceToRepaintBoundary = true;
renderBoxModel!.owner!.flushLayout();
SchedulerBinding.instance!.addPostFrameCallback((_) async {
Uint8List captured;
RenderBoxModel _renderBoxModel = renderBoxModel!;
if (_renderBoxModel.hasSize && _renderBoxModel.size.isEmpty) {
// Return a blob with zero length.
captured = Uint8List(0);
} else {
Image image = await _renderBoxModel.toImage(pixelRatio: devicePixelRatio ?? window.devicePixelRatio);
ByteData? byteData = await image.toByteData(format: ImageByteFormat.png);
captured = byteData!.buffer.asUint8List();
}
completer.complete(captured);
forceToRepaintBoundary = false;
// May be disposed before this callback.
_renderBoxModel.owner?.flushLayout();
});
SchedulerBinding.instance!.scheduleFrame();
return completer.future;
}