flutter_saver 0.0.1+3 flutter_saver: ^0.0.1+3 copied to clipboard
A Flutter package for saving images and downloadable links across all platforms with support for various formats.
This Flutter package provides a powerful and versatile solution for saving camera images and downloadable links across all platforms. With support for various formats, it allows developers to store images and files efficiently in device memory.
Features #
-
You can use this code to save images on any platform.
-
use for local image
FlutterSaver.saveImageWindowsWeb(fileImage: fileImage);
FlutterSaver.saveImageAndroid(fileImage: fileImage);
FlutterSaver.saveImageIos(fileImage: fileImage);
FlutterSaver.saveImageMacOs(fileImage: fileImage);
-Example
await FlutterSaver.saveImageWindowsWeb(
fileImage: fileImage,
fileName: 'example',
type: 'jpg',
);
-
You can use this code to save images on any platform.
-
use for Network
FlutterSaver.saveFileWindowsWeb(link: link);
FlutterSaver.saveFileAndroid(link: link);
FlutterSaver.saveFileIos(link: link);
FlutterSaver.saveFileMac(link: link);
-Example
GestureDetector(
onTap: () async {
Future<bool> isSaved = FlutterSaver.saveFileAndroid(
link:
"https://platinumlist.net/guide/wp-content/uploads/2023/03/IMG-worlds-of-adventure.webp");
if (await isSaved) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Image saved successfully!')),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Failed to save image.')),
);
}
},
child: Image.network(
width: 300,
height: 450,
"https://platinumlist.net/guide/wp-content/uploads/2023/03/IMG-worlds-of-adventure.webp"),
),
- suport this format
{
'image/jpeg': '.jpg',
'image/png': '.png',
'video/mp4': '.mp4',
'application/pdf': '.pdf',
'application/zip': '.zip',
'image/gif': '.gif',
'image/webp': '.webp',
'image/svg+xml': '.svg',
'image/tiff': '.tiff',
'image/vnd.microsoft.icon': '.ico',
'image/vnd.djvu': '.djvu',
'image/vnd.adobe.photoshop': '.psd',
'image/x-ms-bmp': '.bmp',
'image/x-icon': '.ico',
'image/x-ico': '.ico',
'image/x-xbitmap': '.xbm',
'image/x-png': '.png',
'application/x-msdownload': '.exe',
'application/vnd.openxmlformats-officedocument.presentationml.presentation':
'.pptx',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
'.docx',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
'.xlsx',
'.dwg': '.dwg',
};
Getting started #
dependencies:
flutter_saver: ^0.0.1+3
dependencies:
flutter_saver:
git:
url: https://github.com/SwanFlutter/flutter_saver.git
How to use #
import 'package:flutter_saver/flutter_saver.dart';
- Steps:
1-Go to the following path in your project:
android/app/src/main/AndroidManifest.xml
2- Make sure you add the following permissions to the AndroidManifest.xml file:
- For Android versions lower than 33:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
- For Android versions 33 and above (Android 13):
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
- Camera and internet access.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
- Add this line code to application AndroidManifest.xml
android:requestLegacyExternalStorage="true"
<application
android:label="avaterbetter"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true">
iOS #
<key>NSPhotoLibraryUsageDescription</key>
<string>We need access to your photo library to select images for editing.</string>
<key>NSCameraUsageDescription</key>
<string>We need access to your camera to take photos for editing.</string>
macOS installation
Since the macOS implementation uses file_selector
, you will need to
add a filesystem access
entitlement:
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
- Use this code for permissions.
import 'package:permission_handler/permission_handler.dart';
import 'package:device_info_plus/device_info_plus.dart';
Future<void> handlePermissions() async {
// Create an instance of device_info_plus
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
int sdkInt = androidInfo.version.sdkInt;
// Check if permissions have already been granted
if (await Permission.photos.isGranted ||
await Permission.videos.isGranted ||
await Permission.audio.isGranted ||
await Permission.storage.isGranted) {
debugPrint('Permissions already granted.');
return;
}
// Check if permissions are permanently denied
if (await Permission.photos.isPermanentlyDenied ||
await Permission.videos.isPermanentlyDenied ||
await Permission.audio.isPermanentlyDenied ||
await Permission.storage.isPermanentlyDenied) {
// Request permission from settings
openAppSettings();
return;
}
// Check the Android version to determine the type of permissions
if (sdkInt >= 33) {
// Request permissions for Android 13 and above
await Permission.photos.request();
await Permission.videos.request();
await Permission.audio.request();
} else {
// Request storage permission for Android 12 and below
await Permission.storage.request();
}
}
@override
void initState() {
super.initState();
handlePermissions();
}
Additional information #
If you have any issues, questions, or suggestions related to this package, please feel free to contact us at swan.dev1993@gmail.com. We welcome your feedback and will do our best to address any problems or provide assistance. For more information about this package, you can also visit our GitHub repository where you can find additional resources, contribute to the package's development, and file issues or bug reports. We appreciate your contributions and feedback, and we aim to make this package as useful as possible for our users. Thank you for using our package, and we look forward to hearing from you!