MediaStore class

To use Android MediaStore API in Flutter. It supports both read & write operation in every android version. It also requests for appropriate permission, if needed.

Constructors

MediaStore.new()

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

deleteFile({required String fileName, required DirType dirType, required DirName dirName, String? relativePath}) Future<bool>
It will delete existing file if exist. Return true if deleted or return false It will request for user permission if app hasn't permission to delete that file. It will use MediaStore from API level 30 & use direct File below 30
deleteFileUsingUri({required String uriString}) Future<bool>
It will delete existing file using Uri from the given uriString if exist. Return true if deleted or return false It will request for user permission if app hasn't permission to delete that file.
editFile({required String uriString, required String tempFilePath}) Future<bool>
It will edit the file using Uri from the given uriString if exist. Return true upon editing. It will request for user permission if app hasn't permission to edit the file. To use this method, first save the updated file in a temporary location, like app data folder then provide this path. This method then copy file contents from this path and edit it in the particularly location using MediaStore. Then it will delete the temporary file.
getDocumentTree({required String uriString}) Future<DocumentTree?>
Return DocumentTree if the given folder uri exist and have permission to read files from that location To grant read or write in a particular folder use requestForAccess
getFilePathFromUri({required String uriString}) Future<String?>
Return the file path as String if the given uri exist and can return a file path like /storage/emulated/0/Pictures/AnotherFolder/al_aqsa_mosque.jpeg, otherwise null
getFileUri({required String fileName, required DirType dirType, required DirName dirName, String? relativePath}) Future<Uri?>
It will return file Uri if file exist, otherwise null
getPlatformSDKInt() Future<int>
Get running platform sdk int
getUriFromFilePath({required String path}) Future<Uri?>
This method is not meant for using outside the plugin.
isFileDeletable({required String uriString}) Future<bool>
Return true if the file from the given uriString is deletable
isFileExist({required String fileName, required DirType dirType, required DirName dirName, String? relativePath}) Future<bool>
It will return true if the file exist, otherwise false
isFileUriExist({required String uriString}) Future<bool>
Return true if the file from the given uriString exists
isFileWritable({required String uriString}) Future<bool>
Return true if the file from the given uriString is writable
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
readFile({required String fileName, required String tempFilePath, required DirType dirType, required DirName dirName, String? relativePath}) Future<bool>
It will read the file if exists. Return true upon reading. It will request for user permission if app hasn't permission to read the file. To use this method, first create a new file in a temporary location, like app data folder then provide this path. This method then copy file contents to this temporary path to read directy by File. It will use MediaStore from API level 30 & use direct File below 30
readFileUsingUri({required String uriString, required String tempFilePath}) Future<bool>
It will read the file using Uri from the given uriString if exist. Return true upon reading. It will request for user permission if app hasn't permission to read the file. To use this method, first create a new file in a temporary location, like app data folder then provide this path. This method then copy file contents to this temporary path to read directly by File.
requestForAccess({required String? initialRelativePath}) Future<DocumentTree?>
From API level 30, app needs to ask for read or write permission for specific directory. Use this method to get read and write access by file picker. It will return DocumentTree if permission is granted
saveFile({required String tempFilePath, required DirType dirType, required DirName dirName, String? relativePath}) Future<SaveInfo?>
It will create new file or update existing file. It will request for user permission if app hasn't permission to save or edit file in that location. To use this method, first save your file in a temporary location like app data folder then provide this path. This method then copy file contents from this path and save it in the particularly location using MediaStore. Then it will delete the temporary file. It will use MediaStore from API level 30 & use direct File below 30
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

appFolder String
Set app directory like Music/MediaStore.appFolder, Download/MediaStore.appFolder, DCIM/MediaStore.appFolder
getter/setter pair

Static Methods

ensureInitialized() Future<void>
Before calling any methods, call this method to get the platform sdk to initialize MediaStore It should be called only once