file_save_directory 1.0.3 copy "file_save_directory: ^1.0.3" to clipboard
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

  1. 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">
  1. 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" />
  1. Enable Legacy Storage (For Android 10)

    Inside the <application> tag in AndroidManifest.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 #

  1. Import the plugin:
import 'package:file_save_directory/file_save_directory.dart';
  1. 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!

1
likes
130
points
160
downloads

Publisher

unverified uploader

Weekly Downloads

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

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

device_info_plus, flutter, open_file, path, path_provider, permission_handler

More

Packages that depend on file_save_directory

Packages that implement file_save_directory