getSingleCamera method

Future<void> getSingleCamera({
  1. dynamic callBackMultiPickerCamera(
    1. List<PlatformFile> files
    )?,
  2. dynamic callBackPickerCamera(
    1. File file
    )?,
  3. bool? isMultiImage = false,
})

Implementation

Future<void> getSingleCamera(
    {Function(List<PlatformFile> files)? callBackMultiPickerCamera,
    Function(File file)? callBackPickerCamera,
    bool? isMultiImage = false}) async {
  final singlePicker = ImagePicker();
  final pickedImage =
      await singlePicker.pickImage(source: (ImageSource.camera));
  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 (callBackMultiPickerCamera != null) {
        callBackMultiPickerCamera(fileList);
      }
    } else {
      if (callBackPickerCamera != null) {
        callBackPickerCamera(File(
          pickedImage.path,
        ));
      }
    }
  } else {
    showLogI('No Image Selected');
  }
}