getSingleImage method

Future<void> getSingleImage({
  1. dynamic callBackMultiPickerImage(
    1. List<PlatformFile>
    )?,
  2. dynamic callBackPickerImage(
    1. File file
    )?,
  3. bool? isMultiImage = false,
})

Implementation

Future<void> getSingleImage(
    {Function(List<PlatformFile>)? callBackMultiPickerImage,
    Function(File file)? callBackPickerImage,
    bool? isMultiImage = false}) async {
  final singlePicker = ImagePicker();
  final pickedImage =
      await singlePicker.pickImage(source: (ImageSource.gallery));
  if (pickedImage != null) {
    if (isMultiImage == true) {
      List<PlatformFile> fileList = [];
      final files = PlatformFile(
          name: pickedImage.name,
          size: await pickedImage.length(),
          bytes: await pickedImage.readAsBytes(),
          path: pickedImage.path,
          readStream: pickedImage.readAsBytes().asStream());
      fileList.add(files);
      if (callBackMultiPickerImage != null) {
        callBackMultiPickerImage(fileList);
      }
    } else {
      if (callBackPickerImage != null) {
        callBackPickerImage(File(
          pickedImage.path,
        ));
      }
    }
  } else {
    showLogI('No Image Selected');
  }
}