save method
Implementation
Future<String> save({String? name}) async {
RenderRepaintBoundary? boundary = _globalKeyRepaintBoundary.currentContext?.findRenderObject() as RenderRepaintBoundary?;
ui.Image? image = await boundary?.toImage();
ByteData? byteData = await image?.toByteData(format: ui.ImageByteFormat.png);
Uint8List? pngBytes = byteData?.buffer.asUint8List();
String rootPath = (await getTemporaryDirectory()).path;
var fileName = name ?? DateTime.now().millisecondsSinceEpoch.toString();
var path = rootPath + "/" + fileName + ".png";
File file = File(path);
if (file.existsSync()) {
file.deleteSync();
}
if (pngBytes != null) {
file.writeAsBytes(pngBytes);
}
return path;
}