renderImage function

Future<void> renderImage({
  1. Function? onDownloadImagePath,
  2. GlobalKey<SfCartesianChartState>? globalKey,
  3. String? fileName,
})

Generate image

Implementation

Future<void> renderImage(
    {Function? onDownloadImagePath,
    GlobalKey<SfCartesianChartState>? globalKey,
    String? fileName}) async {
  final List<int> bytes = await readImageData(globalKey);
  await getApplicationDocumentsDirectory();
  Directory documentsDirectory = await getApplicationDocumentsDirectory();
  final String path = documentsDirectory.path;
  DateTime currentDatetime = DateTime.now();
  String imageName =
      '${fileName!}_${CalenderDateUtils.fullDateTime(currentDatetime).toString()}.png';
  //printLogs("imageName $imageName");
  imageCache.clear();
  final File file = File('$path/$imageName');
  file.writeAsBytesSync(bytes);
  onDownloadImagePath!.call(file);
}