FileSaverPlatform class abstract
Platform interface for file saver implementations.
This abstract class defines the contract that platform-specific implementations must implement.
Platform implementations:
- iOS/macOS: Uses FFI to call Swift code (shared darwin source)
- Android: Uses JNI to call Kotlin code
- Windows: dart:io, with Known Folders from path_provider_windows and ShellExecuteExW (dart:ffi) to open files
- Linux: dart:io, with XDG user directories from the
xdg-user-dirsubprocess andxdg-opento open files - Web: Uses browser APIs via dart:web + dart:js_interop
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
canOpenFile(
Uri uri) → Future< bool> -
Checks whether the file at
uriis accessible for reading. -
checkSaveLocation<
T extends SaveLocation> (SaveLocation? saveLocation) → T? -
Returns
saveLocationas a location of the running platform,T, or null for the platform's default. Call it after handling PathLocation. -
isTerminal(
SaveProgress e) → bool - Checks if SaveProgress event is terminal.
-
mapDirPickerError(
Object e, String action) → FileSaverException -
Converts an error from
dir_pickerinto a FileSaverException: an ArgumentError (a location the platform can't use) into an InvalidInputException, and anything else into a NativePlatformException that keeps theDirPickerException.code. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
openFile(
Uri uri, {String? mimeType}) → Future< void> - Opens a saved file with the appropriate system app.
-
openWrite(
{required String fileName, required FileType fileType, SaveLocation? saveLocation, String? subDir, int? totalSize, ConflictResolution conflictResolution = ConflictResolution.autoRename}) → Future< FileSaverSink?> - Opens a streaming write session to an auto-resolved location.
-
openWriteAs(
{required String fileName, required FileType fileType, required PickedDirectoryLocation saveLocation, int? totalSize, ConflictResolution conflictResolution = ConflictResolution.autoRename}) → Future< FileSaverSink?> - Opens a streaming write session to a user-selected directory.
-
persistDirectory(
PickedDirectoryLocation location) → Future< String> -
Keeps access to
locationafter the app restarts and returns a token for restoreDirectory. SeeDirPicker.persist. -
pickDirectory(
{bool shouldPersist = true}) → Future< PickedDirectoryLocation?> - Shows the system directory picker.
-
releaseDirectory(
String token) → Future< void> -
Gives up the access a persistDirectory token keeps. See
DirPicker.release. -
restoreDirectory(
String token) → Future< PickedDirectoryLocation?> -
Returns the directory a persistDirectory token points to, with access
to it restored, or null when the token no longer gives access. See
DirPicker.restore. -
saveAs(
{required SaveInput input, required FileType fileType, required String fileName, required PickedDirectoryLocation saveLocation, ConflictResolution conflictResolution = ConflictResolution.autoRename}) → Stream< SaveProgress> - Saves to a user-selected directory with progress streaming.
-
saveBytes(
{required Uint8List fileBytes, required FileType fileType, required String fileName, SaveLocation? saveLocation, String? subDir, ConflictResolution conflictResolution = ConflictResolution.autoRename}) → Stream< SaveProgress> - Saves file bytes to device storage with progress streaming.
-
saveFile(
{required String filePath, required String fileName, required FileType fileType, SaveLocation? saveLocation, String? subDir, ConflictResolution conflictResolution = ConflictResolution.autoRename}) → Stream< SaveProgress> -
Saves a file from
filePathto device storage with progress streaming. -
saveNetwork(
{required String url, required String fileName, required FileType fileType, Map< String, String> ? headers, Duration timeout = const Duration(seconds: 60), SaveLocation? saveLocation, String? subDir, ConflictResolution conflictResolution = ConflictResolution.autoRename}) → Stream<SaveProgress> -
Downloads from
urland saves to device storage with progress streaming. -
toString(
) → String -
A string representation of this object.
inherited
-
validateBytesInput(
Uint8List bytes, String fileName) → void - Validates input for saveBytes.
-
validateFilePathInput(
String filePath, String fileName) → void - Validates input for saveFile.
-
validateNetworkInput(
String url, String fileName) → void - Validates input for saveNetwork.
-
validateSaveAsInput(
{SaveInput? input, required String fileName, required FileType fileType}) → void -
Throws InvalidInputException for input that saveAs (or, with a
null
input, openWriteAs) rejects. FileSaver.saveAs and FileSaver.openWriteAs call it before the directory picker opens, so that the user isn't asked for a directory the save then can't use.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance ↔ FileSaverPlatform
-
The current platform implementation.
getter/setter pair