captureAsFile method

Future<File> captureAsFile({
  1. String path = '',
  2. double pixelRatio = 1,
})

Captures File and saves to given path. Default path is $applicationDocumentsDirectory/$file.png

Implementation

Future<File> captureAsFile({
  String path = '',
  double pixelRatio = 1,
}) async {
  try {
    final boundary = _getRenderRepaintBoundary();

    final pngBytes = await _getPngBytes(boundary, pixelRatio);

    if (path.isEmpty) path = await _getDefaultPath();

    final imgFile = File(path);
    await imgFile.writeAsBytes(pngBytes).then((onValue) {});
    return imgFile;
  } on Exception {
    throw (Exception);
  }
}