easy_gallery_saver 0.0.2 copy "easy_gallery_saver: ^0.0.2" to clipboard
easy_gallery_saver: ^0.0.2 copied to clipboard

Simple Flutter package to save images to gallery with one function call. Supports assets, files, and network images.

example/main.dart

import 'package:flutter/material.dart';
import 'package:easy_gallery_saver/easy_gallery_saver.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Easy Gallery Saver Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  bool _isLoading = false;
  String _statusMessage = '';

  // Rasmni saqlash funksiyasi
  Future<void> _saveImage(String imagePath) async {
    setState(() {
      _isLoading = true;
      _statusMessage = 'Saqlanmoqda...';
    });

    try {
      bool result = await EasyGallerySaver.saveImage(imagePath);

      setState(() {
        _isLoading = false;
        if (result) {
          _statusMessage = '✅ Rasm muvaffaqiyatli saqlandi!';
        } else {
          _statusMessage = '❌ Xatolik yuz berdi';
        }
      });

      // SnackBar ko'rsatish
      if (mounted) {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
            content: Text(
              result ? 'Rasm galereiyaga saqlandi!' : 'Xatolik yuz berdi',
            ),
            backgroundColor: result ? Colors.green : Colors.red,
          ),
        );
      }
    } catch (e) {
      setState(() {
        _isLoading = false;
        _statusMessage = '❌ Xatolik: $e';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Easy Gallery Saver'),
        centerTitle: true,
      ),
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(20.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              // Rasm ko'rsatish
              Container(
                width: 200,
                height: 200,
                decoration: BoxDecoration(
                  color: Colors.grey[300],
                  borderRadius: BorderRadius.circular(12),
                  image: const DecorationImage(
                    image: AssetImage('assets/images/sample.jpg'),
                    fit: BoxFit.cover,
                  ),
                ),
              ),
              const SizedBox(height: 30),

              // Status message
              if (_statusMessage.isNotEmpty)
                Padding(
                  padding: const EdgeInsets.only(bottom: 20),
                  child: Text(
                    _statusMessage,
                    style: const TextStyle(
                      fontSize: 16,
                      fontWeight: FontWeight.bold,
                    ),
                    textAlign: TextAlign.center,
                  ),
                ),

              // Tugmalar
              ElevatedButton.icon(
                onPressed: _isLoading
                    ? null
                    : () => _saveImage('assets/images/sample.jpg'),
                icon: _isLoading
                    ? const SizedBox(
                        width: 20,
                        height: 20,
                        child: CircularProgressIndicator(
                          strokeWidth: 2,
                          color: Colors.white,
                        ),
                      )
                    : const Icon(Icons.save),
                label: Text(_isLoading ? 'Saqlanmoqda...' : 'Rasmni saqlash'),
                style: ElevatedButton.styleFrom(
                  padding: const EdgeInsets.symmetric(
                    horizontal: 30,
                    vertical: 15,
                  ),
                  textStyle: const TextStyle(fontSize: 16),
                ),
              ),
              const SizedBox(height: 20),

              // Info text
              const Text(
                'Tugmani bosing va rasm galereiyaga saqlanadi',
                style: TextStyle(color: Colors.grey, fontSize: 14),
                textAlign: TextAlign.center,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
155
points
174
downloads

Publisher

unverified uploader

Weekly Downloads

Simple Flutter package to save images to gallery with one function call. Supports assets, files, and network images.

Repository (GitHub)
View/report issues

Topics

#gallery #image #save #permission #media

Documentation

API reference

License

MIT (license)

Dependencies

flutter, image_gallery_saver, permission_handler

More

Packages that depend on easy_gallery_saver