media_gallery_saver 1.1.0
media_gallery_saver: ^1.1.0 copied to clipboard
This plug-in allows you to save files to the iOS and Android galleries from url, asset, and file.
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().saveMediaFromFile(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'),
),
],
),
),
),
);
}
}