exportToImage method
Future<Uint8List?>
exportToImage(
- GlobalKey<
State< key, {StatefulWidget> > - double pixelRatio = 3.0,
Implementation
Future<Uint8List?> exportToImage(
GlobalKey key, {
double pixelRatio = 3.0,
}) async {
if (_disposed) return null;
try {
final boundary =
key.currentContext?.findRenderObject() as RenderRepaintBoundary?;
if (boundary == null) return null;
final image = await boundary.toImage(
pixelRatio: pixelRatio.isFinite && pixelRatio > 0 ? pixelRatio : 1.0,
);
final byteData = await image.toByteData(format: ui.ImageByteFormat.png);
return byteData?.buffer.asUint8List();
} catch (_) {
return null;
}
}