saveDownloadedFile method

Future<bool> saveDownloadedFile(
  1. Future<MaterialFileDto> download(
    1. String directory
    ), {
  2. bool canSave()?,
})

Downloads and exports a file, cleaning temporary data on every outcome.

Returns false when cancelled. Serializes downloads and save dialogs so multiple requests cannot open overlapping native pickers.

Implementation

Future<bool> saveDownloadedFile(
  Future<MaterialFileDto> Function(String directory) download, {
  bool Function()? canSave,
}) {
  final task = _saveTail.then(
    (_) => _saveDownloadedFile(download, canSave: canSave),
  );
  _saveTail = task.then<void>((_) {}, onError: (Object _, StackTrace _) {});
  return task;
}