saveImage method
- required File file,
- double pixelRatio = 6,
- ImageByteFormat format = ui.ImageByteFormat.png,
Render a image from widget by this GlobalKey and save it to file
.
Remember to surround your widget with WidgetsToImage and give it this GlobalKey
Implementation
Future<File> saveImage({
required File file,
double pixelRatio = 6,
ui.ImageByteFormat format = ui.ImageByteFormat.png,
}) async {
try {
final image = await renderImageAsBytes(pixelRatio: pixelRatio, format: format);
if ((await file.parent.exists()) == false) {
await file.parent.create(recursive: true);
}
return await file.writeAsBytes(image);
} catch (e) {
rethrow;
}
}