From 7b3ccfe6d249d6bd483af583a01603955170c209 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Sat, 6 Apr 2024 23:24:25 +0200 Subject: [PATCH] clamp zoom to the nearest value --- .../components/camera_container/bloc_container_camera.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 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 56dec48..08bfee4 100644 --- a/lib/screens/metering/components/camera_container/bloc_container_camera.dart +++ b/lib/screens/metering/components/camera_container/bloc_container_camera.dart @@ -169,9 +169,10 @@ class CameraContainerBloc extends EvSourceBlocBase _onZoomChanged(ZoomChangedEvent event, Emitter emit) async { - if (_cameraController != null && event.value >= _zoomRange!.start && event.value <= _zoomRange!.end) { - _cameraController!.setZoomLevel(event.value); - _currentZoom = event.value; + if (_cameraController != null) { + final double zoom = event.value.clamp(_zoomRange!.start, _zoomRange!.end); + _cameraController!.setZoomLevel(zoom); + _currentZoom = zoom; _emitActiveState(emit); } }