toImagePng method
Future<Uint8List?>
toImagePng({
- double pixelRatio = 1.0,
- FutureOr<
void> onError(- Object error,
- StackTrace stackTrace
Implementation
Future<Uint8List?> toImagePng({
double pixelRatio = 1.0,
FutureOr<void> Function(Object error, StackTrace stackTrace)? onError,
}) async {
try {
final RenderRepaintBoundary boundary =
findRenderObject() as RenderRepaintBoundary;
final ui.Image image = await boundary.toImage(
pixelRatio: pixelRatio,
);
final ByteData? byteData =
await image.toByteData(format: ui.ImageByteFormat.png);
if (byteData == null) {
return null;
}
return byteData.buffer.asUint8List();
} catch (e, stack) {
if (onError != null) {
await onError(e, stack);
}
return null;
}
}