From b144cf7edb73659898dbb2a61be52afa85e1918d Mon Sep 17 00:00:00 2001 From: Vadim Date: Fri, 5 May 2023 23:19:24 +0200 Subject: [PATCH] allow nullable ev100 in `CameraContainerBloc` --- .../bloc_container_camera.dart | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/screens/metering/components/camera_container/bloc_container_camera.dart b/lib/screens/metering/components/camera_container/bloc_container_camera.dart index 6d0f88a..75bb6e8 100644 --- a/lib/screens/metering/components/camera_container/bloc_container_camera.dart +++ b/lib/screens/metering/components/camera_container/bloc_container_camera.dart @@ -34,7 +34,7 @@ class CameraContainerBloc extends EvSourceBlocBase _takePhoto() async { - if (_cameraController == null || - !_cameraController!.value.isInitialized || - _cameraController!.value.isTakingPicture) { - return null; - } + bool get _canTakePhoto => !(_cameraController == null || + !_cameraController!.value.isInitialized || + _cameraController!.value.isTakingPicture); + Future _takePhoto() async { try { final file = await _cameraController!.takePicture(); final Uint8List bytes = await file.readAsBytes(); Directory(file.path).deleteSync(recursive: true); final tags = await readExifFromBytes(bytes); - final iso = double.parse("${tags["EXIF ISOSpeedRatings"]}"); - final apertureValueRatio = (tags["EXIF FNumber"]!.values as IfdRatios).ratios.first; + final iso = double.tryParse("${tags["EXIF ISOSpeedRatings"]}"); + final apertureValueRatio = (tags["EXIF FNumber"]?.values as IfdRatios?)?.ratios.first; + final speedValueRatio = (tags["EXIF ExposureTime"]?.values as IfdRatios?)?.ratios.first; + if (iso == null || apertureValueRatio == null || speedValueRatio == null) { + return null; + } + final aperture = apertureValueRatio.numerator / apertureValueRatio.denominator; - final speedValueRatio = (tags["EXIF ExposureTime"]!.values as IfdRatios).ratios.first; final speed = speedValueRatio.numerator / speedValueRatio.denominator; return log2(pow(aperture, 2)) - log2(speed) - log2(iso / 100);