file_save_directory 1.0.3
file_save_directory: ^1.0.3 copied to clipboard
A Flutter plugin for saving files to Downloads, Documents, Music, Videos, or App Documents folders on Android and iOS with enum-based location selection and smart file type detection
file_save_directory #
A Flutter plugin that allows you to save files to the Downloads, Documents, Music, Videos, or App Documents directories on Android and iOS. It also supports automatically opening the file after saving, handles permissions, and resolves file name conflicts.
β¨ Features #
- β
Save files to:
- π Public Downloads folder
- π Public Documents folder
- π΅ Public Music folder
- π¬ Public Videos folder
- π App's private documents directory
- π‘οΈ Automatically handles permissions and file name conflicts
- π± Supports Android 6.0+ and iOS 11+
- π¦ Simple API β just provide a file name and bytes
- π Optionally opens the file after saving
- π΅ Smart detection for audio and video file types
Platform Support #
- β Android 6.0+ (API level 23)
- β iOS 11+
π Getting Started #
βοΈ Platform Setup #
β Android Setup
-
Update AndroidManifest.xml in
android/app/src/main/AndroidManifest.xml:First, ensure your manifest declaration includes the required namespaces:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
- Add permissions (inside
<manifest>, but outside<application>):
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />
-
Enable Legacy Storage (For Android 10)
Inside the
<application>tag inAndroidManifest.xml, add:
<application
...
android:requestLegacyExternalStorage="true"
...
>
</application>
π iOS Setup
Add the following keys to your ios/Runner/Info.plist file:
<key>UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
These keys enable file sharing and document interaction for your iOS app.
π‘ Usage #
- Import the plugin:
import 'package:file_save_directory/file_save_directory.dart';
- Save a file:
final result = await FileSaveDirectory.instance.saveFile(
fileName: 'example.txt',
fileBytes: utf8.encode('Hello, Flutter!'),
location: SaveLocation.downloads, // or SaveLocation.documents, SaveLocation.music, SaveLocation.videos, SaveLocation.appDocuments
openAfterSave: true, // Default to true
);
π Save Location Options #
- ποΈ SaveLocation.downloads β π Public Downloads (Android), π Documents (iOS)
- π SaveLocation.documents β π Public Documents (Android), π Documents (iOS)
- π΅ SaveLocation.music β π΅ Public Music folder (Android), π΅ App's Music folder (iOS)
- π¬ SaveLocation.videos β π¬ Public Movies/Videos folder (Android), π¬ App's Videos folder (iOS)
- π SaveLocation.appDocuments β π¦ App's private documents folder (Android & iOS)
π Troubleshooting #
β Android 11+ requires MANAGE_EXTERNAL_STORAGE for full shared storage access.
π If saving fails, ensure your app has storage permissions.
π± Test on a real device to validate file system behavior.
βοΈ Call FileSaveDirectory.instance.openAppSettings() if you need to prompt users to manually grant storage access.
π€ Contributing #
Feel free to open issues or submit pull requests. All contributions are welcome!