2024
gallery_saver and its forked packages (like image_gallery_saver) are outdated.
We should use gal instead.
await Gal.putImage(path);
await Gal.putVideo(path);
Incidentally, the temporary directory can be obtained without using path_provider, just with this code
Directory.systemTemp.path;
Some people try to save the media in the project's asset folder, so I leave the code for that as well.
final byteData = await rootBundle.load('assets/image.jpg');
final file = await File('${Directory.systemTemp.path}${path.replaceAll('assets', '')}').create();
await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
await Gal.putImage(file.path);
It works for both Android and iOS. More info can be found in the example of the gal package.
Thank you.