saveImageToGallery method
- @Category(['Gallery'])
- Uint8List imageBytes, {
- required GalleryImageSaveOptions options,
Saves an image to the gallery app on supported platforms. Supports Android, iOS, and macOS.
Requires Android, iOS and macOS setup. See Saving images to the gallery for more details.
Requests necessary permission if not already granted on Android 9 (API 28) and earlier, iOS, and macOS. On Android 10 (Api 29) and later, the plugin makes use of the Android scoped storage.
NOTE: On macOS, permission is denied if the app is running using sources other than Xcode or macOS terminal such as Android Studio or VS Code. However, this does not affect the final production app.
The GalleryImageSaveOptions.name is the image's name without the extension (e.g., image
).
It doesn't need to be unique, as it's handled by the gallery/system.
The GalleryImageSaveOptions.fileExtension is the image's file extension (e.g., png
).
This is silently ignored on macOS and iOS.
On Android 10 (API 29) and later, it determines the image MIME type.
On Android 9 (API 28) and earlier, it is used as the file name
and to extract the MIME type.
The GalleryImageSaveOptions.albumName sets the album in the gallery app.
A new album will be created if it doesn't exist.
If null
, the default album is used.
If not null
, read-write access to the photos library is always
required on iOS and macOS (even on newer versions where add-only is supported).
Calling this on unsupported platforms will throw UnimplementedError. Calling this on macOS 10.14 and earlier will throw UnsupportedError (unsupported by the platform).
Use isSupported to check before calling:
if (await isSupported(QuillNativeBridgeFeature.saveImageToGallery)) {
// The method saveImageToGallery() is both implemented and supported by the device / OS version.
// Call saveImageToGallery()
}
See also saveImage to save the image on desktop and web platforms.
Implementation
@Category(['Gallery'])
Future<void> saveImageToGallery(
Uint8List imageBytes, {
required GalleryImageSaveOptions options,
}) =>
_platform.saveImageToGallery(imageBytes, options: options);