getFilePathFromPicker method

Future<String?> getFilePathFromPicker({
  1. required BuildContext context,
  2. required ImageSource? source,
  3. double maxHeight = 1024,
  4. double maxWidth = 1024,
})

Implementation

Future<String?> getFilePathFromPicker({
  required BuildContext context,
  required ImageSource? source,
  double maxHeight = 1024,
  double maxWidth = 1024,
}) async {
  if (source == null) return null;

  try {
    if (source == ImageSource.camera) {
      final XFile? image = await ImagePicker().pickImage(
        source: ImageSource.camera,
        maxHeight: maxHeight,
        maxWidth: maxWidth,
      );
      return image?.path;
    } else if (source == ImageSource.gallery) {
      final XFile? image =
          await ImagePicker().pickImage(source: ImageSource.gallery);
      return image?.path;
    }
    return null;
  } on PlatformException catch (error) {
    if (enableFilePickerExceptionHandler == false) rethrow;

    if (error.code == 'photo_access_denied') {
      // errorToast(
      //   context: context,
      //   title: T.galleryAccessDeniedTitle.tr,
      //   message: T.galleryAccessDeniedContent.tr,
      // );
    } else if (error.code == 'camera_access_denied') {
      // errorToast(
      //   context: context,
      //   title: T.cameraAccessDeniedTitle.tr,
      //   message: T.cameraAccessDeniedContent.tr,
      // );
    } else {
      /// rethrow the unhandled error from PlatformException if there's any
      rethrow;
    }
  } catch (e) {
    rethrow;
  }
  return null;
}