Saf
Flutter plugin that leverages Storage Access Framework (SAF) API to get access and perform the operations on files and folders.
Currently supported features
- Uses OS default native file explorer
- Access the hidden folder and files
- Accessing directories
- Caching the files inside the app External files directory
- Syncing the files of some directory with cached one
- Different default type filtering (media, image, video, audio or any)
- Support Android
If you have any feature that you want to see in this package, please feel free to issue a suggestion.
Usage
To use this plugin, add saf
as a dependency in your pubspec.yaml file.
Initiate Saf with instance
Saf saf = Saf(directoryPath: "~/some/path")
Directory Permission request
bool? isGranted = await saf.getDirectoryPermission(isDynamic: false);
if (isGranted != null) {
// Perform some file operations
} else {
// User canceled the native explorer
}
Get paths of all the files of granted directory
List<String>? paths = await saf.getFilesPath(FileType.media);
Cache the granted directory
List<String>? cachedFilesPath = await saf.cache();
Get the cached files' path
List<String>? cachedFilesPath = await saf.getCachedFilesPath();
Cache a single file of the granted directory
String? path = await saf.singleCache(filePath: "~/some/path/file.type");
Clear cache of the granted directory
bool? isClear = await saf.clearCache();
Sync the cached directory with the granted directory
bool? isSynced = await saf.syncWithCacheDirectory();
Release the persisted permission for current granted directory
bool? isReleased = await saf.releasePersistedPermission();
Get the list of all the granted directory paths with persisted permissions
// Static method
List<String>? paths = await Saf.getPersistedPermissionDirectories();
Release the persisted permissions for all granted the directories
// Static method
bool? isReleased = await Saf.releasePersistedPermissions();
Documentation
See the Saf Wiki for every detail on about how to install, setup and use it.
Saf Wiki
For full usage details refer to the Wiki above.
Example App
Android
Compatibility Chart
API | Android | iOS | Windows | linux | macOS |
---|---|---|---|---|---|
getDirectoryPermission() | |
|
|
|
|
getFilesPath() | |
|
|
|
|
getCachedFilesPath() | |
|
|
|
|
cache() | |
|
|
|
|
singleCache() | |
|
|
|
|
clearCache() | |
|
|
|
|
syncWithCacheDir() | |
|
|
|
|
getPersistedPermissionDirectories() | |
|
|
|
|
releasePersistedPermissions() | |
|
|
|
|
See the API section of the Saf Wiki or the official API reference on pub.dev for further details.
Getting Started
For help getting started with Flutter, view our online documentation.
For help on editing plugin code, view the documentation.