pickImagesFromDevice method

Future<List<File?>> pickImagesFromDevice({
  1. required ImageSource source,
  2. CameraDevice? preferredCameraDevice,
})

Returns a human-readable string representation of the size of the specified file in bytes, using the filesize package. If the File is null, the method returns an empty string. pickImagesFromDevice Launches image picker to allow user to select one or multiple images from their device

source specifies where to get the images from, either the gallery or the camera.

preferredCameraDevice specifies which camera to use in case the user selects the camera as the source.

Returns a list of File objects containing the selected images.

Example usage:

List<File?> images = await RhUtils.instance.pickImagesFromDevice(source: ImageSource.camera);

Implementation

/// [pickImagesFromDevice] Launches image picker to allow user to select one or multiple images from their device
///
/// [source] specifies where to get the images from, either the gallery or the camera.
///
/// [preferredCameraDevice] specifies which camera to use in case the user selects the camera as the source.
///
/// Returns a list of [File] objects containing the selected images.
///
/// Example usage:
/// ```
/// List<File?> images = await RhUtils.instance.pickImagesFromDevice(source: ImageSource.camera);
/// ```
Future<List<File?>> pickImagesFromDevice({
  required ImageSource source,
  CameraDevice? preferredCameraDevice,
}) async {
  List<File?> files = [];
  final image = await ImagePicker().pickImage(
      source: source,
      preferredCameraDevice: preferredCameraDevice ?? CameraDevice.rear);
  if (image == null) return files;
  File? img = File(image.path);
  files.add(img);
  return files;
}