diff --git a/packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart b/packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart index 02181ca1a4f..8b6fe35587f 100644 --- a/packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart +++ b/packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart @@ -129,16 +129,19 @@ class MLKitScannerPageState extends State { _controller?.setFocusMode(FocusMode.auto); _controller?.lockCaptureOrientation(DeviceOrientation.portraitUp); - _controller = _controller; - - try { - await _controller!.initialize(); + // If the controller is initialized update the UI. + _controller?.addListener(() { if (mounted) { setState(() {}); } if (_controller!.value.hasError) { + // TODO(M123): Handle errors better debugPrint(_controller!.value.errorDescription); } + }); + + try { + await _controller?.initialize(); _controller?.startImageStream(_processCameraImage); } on CameraException catch (e) { if (kDebugMode) { @@ -146,7 +149,6 @@ class MLKitScannerPageState extends State { debugPrint(e.toString()); } } - if (mounted) { setState(() {}); } @@ -154,7 +156,9 @@ class MLKitScannerPageState extends State { Future _stopImageStream() async { stoppingCamera = true; - setState(() {}); + if (mounted) { + setState(() {}); + } await _controller?.dispose(); _controller = null; }