flutter_file_saver 0.9.0
flutter_file_saver: ^0.9.0 copied to clipboard
Interface to provide a way to save files on the device in Flutter.
flutter_file_saver #
Interface to provide a way to save files on the device in Flutter.
Platform Support #
| Android | iOS | Web | Windows | Linux | MacOS | |
|---|---|---|---|---|---|---|
writeFileAsBytes |
✅ | ✅ | ✅ | ❌️ | ❌️ | ✅ |
writeFileAsString |
✅ | ✅ | ✅ | ❌️ | ❌️ | ✅ |
Under the hood, each implementation tries to use the native dialog to save the file:
- Android:
ACTION_CREATE_DOCUMENTintent is used - iOS:
UIDocumentPickerViewControlleris used - MacOS:
NSSavePanelis used - Web: It will try to use the
showSaveFilePickerAPI if available, otherwise it will try to use thedownloadattribute on an anchor tag
Getting Started #
Import the package #
dependencies:
flutter_file_saver: any
Platform Setup #
iOS Setup (Needs iOS 16+)
Add the following permissions to your ios/Runner/Info.plist:
<key>UISupportsDocumentBrowser</key>
<true/>
<key>UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
MacOS Setup
Add the following permissions to your macos/Runner/DebugProfile.entitlements:
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
Methods #
writeFileAsBytes #
Write a file on the device from a Uint8List.
FlutterFileSaver().writeFileAsBytes(
fileName: 'file.txt',
bytes: fileBytes,
);
writeFileAsString #
Write a file on the device from a String. This will most of the time convert your data and perform a call to writeFileAsBytes.
FlutterFileSaver().writeFileAsString(
fileName: 'file.txt',
string: 'Hello World!',
);