takePhoto method

Future<UCapturedPhoto?> takePhoto({
  1. String? path,
  2. UPhotoFormat? format,
  3. int? quality,
  4. bool? mirror,
  5. bool includeBytes = true,
  6. bool includeThumbnail = false,
  7. UCameraSize? maxSize,
})

Implementation

Future<UCapturedPhoto?> takePhoto({
  String? path,
  UPhotoFormat? format,
  int? quality,
  bool? mirror,
  bool includeBytes = true,
  bool includeThumbnail = false,
  UCameraSize? maxSize,
}) async {
  final int? id = _sessionId;
  if (id == null) return null;
  _emit(value.copyWith(state: UCameraState.capturing));
  try {
    final Map<Object?, Object?>? raw = await UCameraChannel.invokeMap("takePhoto", <String, Object?>{
      "sessionId": id,
      "path": path,
      "format": (format ?? _config.photoFormat).name,
      "quality": quality ?? _config.photoQuality,
      "mirror": mirror ?? _config.mirrorFrontCapture,
      "includeBytes": includeBytes,
      "includeThumbnail": includeThumbnail,
      "maxSize": maxSize?.toMap(),
    });
    _emit(value.copyWith(state: UCameraState.ready));
    return raw == null ? null : UCapturedPhoto.fromMap(raw);
  } on UCameraException catch (error) {
    _emit(value.copyWith(state: UCameraState.ready));
    _fail(error);
    return null;
  } catch (error) {
    _emit(value.copyWith(state: UCameraState.ready));
    _fail(UCameraException(code: UCameraErrorCode.unknown, message: "$error"));
    return null;
  }
}