openCamera method

  1. @override
Future<HLPickerItem> openCamera({
  1. HLCameraOptions? cameraOptions,
  2. bool? cropping,
  3. HLCropOptions? cropOptions,
  4. LocalizedImageCropper? localized,
})

Take a photo or record a video

cameraOptions: Additional options for the camera functionality: cameraType, recordVideoMaxSecond, isExportThumbnail...

cropping: Indicating whether or not cropping is enabled

cropOptions: Configuration options for the cropping functionality: aspectRatio, aspectRatioPresets, compressQuality, compressFormat

localized: Custom text displayed for the plugin

Returns a HLPickerItem object

Implementation

@override
Future<HLPickerItem> openCamera({
  HLCameraOptions? cameraOptions,
  bool? cropping,
  HLCropOptions? cropOptions,
  LocalizedImageCropper? localized,
}) async {
  double? cropCompressQuality = cropOptions?.compressQuality;
  assert(cropCompressQuality == null ||
      (cropCompressQuality > 0 && cropCompressQuality <= 1));

  int? cameraWidth = cameraOptions?.maxSizeOutput?.maxWidth;
  assert(cameraWidth == null || cameraWidth >= 10);

  int? cameraHeight = cameraOptions?.maxSizeOutput?.maxHeight;
  assert(cameraHeight == null || cameraHeight >= 10);

  int? cropWidth = cropOptions?.maxSizeOutput?.maxWidth;
  assert(cropWidth == null || cropWidth >= 10);

  int? cropHeight = cropOptions?.maxSizeOutput?.maxHeight;
  assert(cropHeight == null || cropHeight >= 10);

  const defaultPresets = [
    CropAspectRatioPreset.original,
    CropAspectRatioPreset.square,
    CropAspectRatioPreset.ratio3x2,
    CropAspectRatioPreset.ratio4x3,
    CropAspectRatioPreset.ratio16x9
  ];

  final data = await methodChannel.invokeMethod('openCamera', {
    'cameraType': cameraOptions?.cameraType?.name,
    'cropping': cropping,
    'ratioX': cropOptions?.aspectRatio?.ratioX,
    'ratioY': cropOptions?.aspectRatio?.ratioY,
    'aspectRatioPresets': (cropOptions?.aspectRatioPresets ?? defaultPresets)
        .map((e) => e.value)
        .toList(),
    'cropCompressQuality': cropOptions?.compressQuality,
    'cropCompressFormat': cropOptions?.compressFormat?.name,
    'recordVideoMaxSecond': cameraOptions?.recordVideoMaxSecond,
    'isExportThumbnail': cameraOptions?.isExportThumbnail,
    'thumbnailCompressQuality': cameraOptions?.thumbnailCompressQuality,
    'thumbnailCompressFormat': cameraOptions?.thumbnailCompressFormat?.name,
    'croppingStyle': cropOptions?.croppingStyle?.name,
    'cropMaxWidth': cropWidth,
    'cropMaxHeight': cropHeight,
    'localized': localized?.toMap(),
    'cameraCompressQuality': cameraOptions?.compressQuality,
    'cameraCompressFormat': cameraOptions?.compressFormat?.name,
    'cameraMaxWidth': cameraWidth,
    'cameraMaxHeight': cameraHeight,
  });
  return HLPickerItem.fromMap(data);
}