Easy Gallery Saver

pub package License: MIT

A simple and easy-to-use Flutter package for saving images to the device gallery. Save images from assets, files, or network URLs with just one function call!

Rasmlarni galereiyaga saqlash uchun oddiy va qulay Flutter package. Asset, file yoki internetdan rasmlarni bir funksiya chaqiruvi bilan saqlang!

Features

✅ Save images from assets
✅ Save images from file system
✅ Save images from network URLs
✅ Automatic permission handling (Android & iOS)
✅ Simple one-function API
✅ Cross-platform support (Android, iOS)

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  easy_gallery_saver: ^0.0.1

Then run:

flutter pub get

Usage

1. Import the package

import 'package:easy_gallery_saver/easy_gallery_saver.dart';

2. Save an image

// Save image from assets
bool saved = await EasyGallerySaver.saveImage('assets/images/photo.jpg');

if (saved) {
  print('Image saved successfully!');
} else {
  print('Failed to save image');
}
// Save image from file path
bool saved = await EasyGallerySaver.saveImage('/storage/emulated/0/Pictures/photo.jpg');
// Save image from network URL
bool saved = await EasyGallerySaver.saveImage('https://example.com/image.jpg');

3. Complete Example with Button

ElevatedButton(
  onPressed: () async {
    bool result = await EasyGallerySaver.saveImage('assets/images/my_photo.jpg');
    
    if (result) {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text('Image saved to gallery!')),
      );
    }
  },
  child: Text('Save Image'),
)

Platform Configuration

Android Setup

Add the following permissions to your android/app/src/main/AndroidManifest.xml:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />

iOS Setup

Add the following keys to your ios/Runner/Info.plist:

<key>NSPhotoLibraryAddUsageDescription</key>
<string>We need permission to save images to your photo library</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>We need permission to access your photo library</string>

API Reference

EasyGallerySaver.saveImage()

static Future<bool> saveImage(String imagePath)

Parameters:

  • imagePath (String): Path to the image. Can be:
    • Asset path: 'assets/images/photo.jpg'
    • File path: '/storage/emulated/0/Pictures/photo.jpg'
    • Network URL: 'https://example.com/image.jpg'

Returns:

  • Future<bool>: Returns true if image was saved successfully, false otherwise.

Requirements

  • Flutter SDK: >=3.0.0
  • Dart SDK: >=3.10.0
  • Android: API level 21+
  • iOS: 11.0+

License

MIT License - see the LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Issues

If you encounter any problems, please file an issue on GitHub.

Libraries