Lock & release focus when taking a picture

This commit is contained in:
Vadim 2023-08-03 22:46:01 +02:00
parent 50c2460f16
commit c12cfb1697

View file

@ -129,7 +129,6 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
await _cameraController!.initialize(); await _cameraController!.initialize();
await _cameraController!.setFlashMode(FlashMode.off); await _cameraController!.setFlashMode(FlashMode.off);
await _cameraController!.setFocusMode(FocusMode.locked);
_zoomRange = await Future.wait<double>([ _zoomRange = await Future.wait<double>([
_cameraController!.getMinZoomLevel(), _cameraController!.getMinZoomLevel(),
@ -206,7 +205,13 @@ class CameraContainerBloc extends EvSourceBlocBase<CameraContainerEvent, CameraC
Future<double?> _takePhoto() async { Future<double?> _takePhoto() async {
try { try {
// https://github.com/flutter/flutter/issues/84957#issuecomment-1661155095
await _cameraController!.setFocusMode(FocusMode.locked);
await _cameraController!.setExposureMode(ExposureMode.locked);
final file = await _cameraController!.takePicture(); final file = await _cameraController!.takePicture();
await _cameraController!.setFocusMode(FocusMode.auto);
await _cameraController!.setExposureMode(ExposureMode.auto);
final Uint8List bytes = await file.readAsBytes(); final Uint8List bytes = await file.readAsBytes();
Directory(file.path).deleteSync(recursive: true); Directory(file.path).deleteSync(recursive: true);