-
Notifications
You must be signed in to change notification settings - Fork 105
Home
This plugin package is not much but only for saving files in Android, iOS, Web, Windows, MacOS and Linux. The package depends on path_provider for Android and iOS and basic html anchor for Web The main reason I built this plugin was to avoid using html only for downloading files. The plugin is pretty simple and saves the file in Downloads folder in Windows, MacOS, Linux and directly downloads the file in Web, in iOS, the file is Saved in Application Documents Directory, and in Android it is saved in the applications files directory Android/data/your.package.name/file/your_file.extension.
The plugin itself is pretty easy to use. Just call the method saveFile() with respective arguments.
await FileSaver.instance.saveFile({
required String name,
Uint8List? bytes,
File? file,
String? filePath,
String? link,
String ext = "",
MimeType mimeType = MimeType.other});
This saveFile() method has 7 Name arguments.
String name which takes the name of the file,
Uint8List bytes which will be your actual encoded file,
Or
File file which will be your file in the File object (from dart:io)
Or
Stirng filePath which will be your file path
Or
String link which will the link to your file
Out of these parameters, you will have to use atleast one
String ext this will be your file extension.
Another parameter is MimeType type Specifically for Web, which will be your file
type
MimeType is also included in my Package, I've included types for Sheets, Presentation, Word, Plain Text, PDF, MP3, MP4 and many other common formats
or you can call saveAs() only available for android and iOS at the moment
await FileSaver.instance.saveAs({
required String name,
Uint8List? bytes,
File? file,
String? filePath,
String? link,
required String ext,
required MimeType mimeType});
All the parameters in this method is same as the saveFile() method.
Go to your project folder, ios/Runner/info.plist and Add these keys:
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>UIFileSharingEnabled</key>
<true/>
Open Your Project in XCode (Open XCode -> Open a project or file -> Your_Project_Folder/ios/Runner.xcworkspace) Open info.plist Add these rows:
Application supports iTunes file sharing (Boolean -> Yes)
Supports opening documents in place (Boolean -> Yes)
Go to your project folder, macOS/Runner/DebugProfile.entitlements
For release you need to open 'YOUR_PROJECT_NAME'Profile.entitlements
and add the following key:
<key>com.apple.security.files.downloads.read-write</key>
<true/>
Open Your Project in XCode (Open XCode -> Open a project or file -> Your_Project_Folder/macos/Runner.xcworkspace) Open your entitlement file (DebugProfile.entitlements & 'YOUR_PROJECT_NAME'Profile.entitlements)
Add these rows:
and if you get Client Socket Exception while saving files in MacOS from link, you have to add this key in the DebugProfile.entitlements and Release.entitlements of your macOS application and set the value to true
<key>com.apple.security.network.client</key>
<true/>
You can find these files in project_folder/macos/Runner/