saveAs static method

Stream<SaveProgress> saveAs({
  1. required SaveInput input,
  2. required FileType fileType,
  3. required String fileName,
  4. PickedDirectoryLocation? saveLocation,
  5. ConflictResolution conflictResolution = ConflictResolution.autoRename,
})

Saves to a user-selected directory with progress streaming.

Platforms: Android · iOS · macOS · Windows · Linux · Web

If saveLocation is null, shows the directory picker first. Yields SaveProgressCancelled if the picker is dismissed. Cancelling the subscription works as in save, and the stream is single-subscription too.

Web: falls back to anchor-download if the browser has no showDirectoryPicker() (Firefox, Safari). Other picker errors, such as a missing user gesture, are reported as SaveProgressError.

fileName works as in save. Invalid input, such as empty bytes or a non-HTTP URL, throws InvalidInputException when saveAs is called, as with save, before the picker opens.

Implementation

static Stream<SaveProgress> saveAs({
  required SaveInput input,
  required FileType fileType,
  required String fileName,
  PickedDirectoryLocation? saveLocation,
  ConflictResolution conflictResolution = ConflictResolution.autoRename,
}) {
  final baseName = _baseName(fileName, fileType);
  _platform.validateSaveAsInput(
    input: input,
    fileName: baseName,
    fileType: fileType,
  );
  return _saveAs(
    input: input,
    fileType: fileType,
    fileName: baseName,
    saveLocation: saveLocation,
    conflictResolution: conflictResolution,
  );
}