pickGalleryImage static method

Future<String> pickGalleryImage(
  1. ImagePicker picker
)

Launches the device gallery/photo library to select an image.

Opens the device's gallery application and allows the user to select an existing image. Returns the file path of the selected image.

Parameters:

  • picker: An ImagePicker instance to handle the gallery interaction

Returns the file path (String) of the selected image.

Throws an exception if the user cancels or if gallery access is denied.

Example:

final picker = ImagePicker();
try {
  final imagePath = await RtCommonFunction.pickGalleryImage(picker);
  print('Image selected from: $imagePath');
} catch (e) {
  print('Gallery cancelled or error: $e');
}

See also:

Implementation

static Future<String> pickGalleryImage(ImagePicker picker) async {
  final XFile? pickedFile =
      await picker.pickImage(source: ImageSource.gallery);
  return pickedFile!.path;
}