saveImage method

Future<ImageSaveResult> saveImage(
  1. Uint8List imageBytes, {
  2. required ImageSaveOptions options,
})

Saves an image to the user's device based on the platform:

  • Web: Downloads the image using the browser's download functionality.
  • macOS: Opens the native save dialog using NSSavePanel, defaulting to the user's Pictures directory. Requires platform setup. Refer to Saving images.
  • Linux and Windows: Opens the native save dialog, defaulting to the user's Pictures directory. The plugin delegates to file_selector_linux or file_selector_windows with the appropriate file type set.

Not supported on mobile platforms (use saveImageToGallery instead). Calling this on unsupported platforms will throw UnimplementedError.

The ImageSaveOptions.name represents the image name without the extension (e.g., image). On web, the browser handles name conflicts. On macOS and Windows, prompts the user to confirm file overwrite. On Linux, behavior depends on the desktop environment (e.g., Gnome, KDE), and file overwrite confirmation may be skipped.

The ImageSaveOptions.fileExtension specifies the file extension (e.g., png) for saving the image on all platforms. Also used to determine the MIME type on Linux and the web.

Returns ImageSaveResult where:

  • ImageSaveResult.filePath: For desktop platforms, null if the user cancels the operation while selecting the destination using the system file picker. Always null on web platforms.

  • ImageSaveResult.blobUrl: For web platforms, returns the blob object URL (e.g., blob:http://localhost:64030/e58f63d4-2890-469c-9c8e-69e839da6a93), which will be revoked before returning it. Always null on non-web platforms.

See also saveImageToGallery for platforms with a native gallery app.

Implementation

Future<ImageSaveResult> saveImage(
  Uint8List imageBytes, {
  required ImageSaveOptions options,
}) =>
    _platform.saveImage(imageBytes, options: options);