getFile method

Future<void> getFile(
  1. String url, {
  2. required GetStorage getStorage,
})

Implementation

Future<void> getFile(String url, {required GetStorage getStorage}) async {
  _snapshot.filePath = null;
  _snapshot.status = DownloadStatus.loading;
  _onSnapshotChanged(_snapshot);

  final cmi = await loadMedia(url, getStorage: getStorage);
  final filePath = cmi?.cachedMediaUrl;
  if (filePath != null) {
    final file = File(filePath);
    if (await file.exists()) {
      _snapshot.filePath = filePath;
      _snapshot.status = DownloadStatus.success;
      _onSnapshotChanged(_snapshot);
    } else {
      _onSnapshotChanged(_snapshot..status = DownloadStatus.error);
    }
  } else {
    _onSnapshotChanged(_snapshot..status = DownloadStatus.error);
  }
}