filesaverz 2.0.0 filesaverz: ^2.0.0 copied to clipboard
A package that makes it easy for user to browse folder and save file or pick files in android.
File Saver Z #
A package that makes it easy for user to browse folder and save file or pick files in android.
Preview #
Install #
Add this to your dependency
dependencies:
filesaverz: ^2.0.0
Continue by adding permission in your AndroidManifest.xml
.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
And then import the filesaver (with z) package.
import 'package:filesaverz/filesaverz.dart';
Usage #
First, setting up the FileSaver widget like this.
FileSaver fileSaver = FileSaver(
fileTypes: const ['txt','pdf'],
initialFileName: 'Untitled File',
);
or this customable FileSaver.
FileSaver fileSaver = FileSaver.builder(
fileTypes: const ['txt','pdf'],
initialFileName: 'Untitled File',
headerBuilder: (context, state) => /* Your Widget */,
bodyBuilder: (context, state) => /* Your Widget */,
footerBuilder: (context, state) => /* Your Widget */,
);
And then in async function call these:
Purpose | Code |
Getting selected path from saving file. |
String? path = await fileSaver.getPath(context);
|
Calling writeAsBytes method. |
fileSaver.writeAsBytes(bytes, context: context);
|
Calling writeAsBytesSync method. |
fileSaver.writeAsBytesSync(bytes, context: context);
|
Calling writeAsString method. |
fileSaver.writeAsString(contents, context: context);
|
Calling writeAsStringSync method. |
fileSaver.writeAsStringSync(contents, context: context);
|
Picking single file. |
File? file = await filePicker.pickFile(context);
|
Picking multiple files. |
List<File>? files = await filePicker.pickFiles(context);
|
Documentation #
Property | Code |
headerBuilder, an optional builder. |
(context, state) {
return Text('My Custom Header Widget');
},
|
bodyBuilder, an optional builder. |
(context, state) {
return Text('My Custom Body Widget');
},
|
footerBuilder, an optional builder |
(context, state) {
return Text('My Custom Footer Widget');
},
|
style, set custom Color, TextStyle and Icon |
FileSaverStyle(
primaryColor: Colors.blue,
secondaryColor: Colors.white,
primaryTextStyle: TextStyle(),
secondaryTextStyle: TextStyle(),
icons: [
FileSaverIcon(icon: (path) => Icon(Icons.default)),
FileSaverIcon.directory(icon: (path) => Icon(Icons.folder)),
FileSaverIcon.file(fileType: 'jpg', icon: (path) => Image.file(File(path)),
]
),
|
initialFileName, this property is used when you call saving method. |
'Untitled File',
|
initialDirectory, in Android by default it's calling Environment.getExternalStorageDirectory. |
Directory('Storage Path'),
|
fileTypes, in saving method this fileTypes used as an option for user to set the desired fileTypes to write. But in picking file method. this property is used to limit what kind of fileTypes that we want to display. |
const ['jpg','gif','png'],
|
Full Documentation here.