media_gallery_saver 1.0.0 copy "media_gallery_saver: ^1.0.0" to clipboard
media_gallery_saver: ^1.0.0 copied to clipboard

This plug-in allows you to save files to the iOS and Android galleries.If authorization is required when saving, an authorization dialog will appear.

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:media_gallery_saver/media_gallery_saver.dart';
import 'package:path_provider/path_provider.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    onPressed() async {
      final tempDir = await getTemporaryDirectory();
      final tempFilePath = '${tempDir.path}/test.png';

      ByteData byteData = await rootBundle.load('assets/test.png');
      final buffer = byteData.buffer;
      File file = File(tempFilePath);
      await file.writeAsBytes(
        buffer.asUint8List(
          byteData.offsetInBytes,
          byteData.lengthInBytes,
        ),
      );

      MediaGallerySaver().saveMedia(
        file: file,
      );
    }

    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              const Text('media_gallery_saver'),
              const SizedBox(height: 20),
              Image.asset(
                'assets/test.png',
                width: 200,
                height: 200,
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                onPressed: onPressed,
                child: const Text('Save'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
0
points
32
downloads

Publisher

verified publishercam-inc.dev

Weekly Downloads

This plug-in allows you to save files to the iOS and Android galleries.If authorization is required when saving, an authorization dialog will appear.

License

unknown (license)

Dependencies

flutter, path

More

Packages that depend on media_gallery_saver

Packages that implement media_gallery_saver