From 589c852812403099760897ed8c9c6049af63e337 Mon Sep 17 00:00:00 2001 From: Khoren Markosyan Date: Fri, 30 Sep 2022 10:23:34 +0400 Subject: [PATCH] fixed camera lifecycle issues --- lib/src/ui/reader_widget.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/src/ui/reader_widget.dart b/lib/src/ui/reader_widget.dart index 38feecb..ef09215 100644 --- a/lib/src/ui/reader_widget.dart +++ b/lib/src/ui/reader_widget.dart @@ -86,6 +86,11 @@ class _ReaderWidgetState extends State @override void didChangeAppLifecycleState(AppLifecycleState state) { + final CameraController? cameraController = controller; + if (cameraController == null || !cameraController.value.isInitialized) { + return; + } + switch (state) { case AppLifecycleState.resumed: if (cameras.isNotEmpty && !_cameraOn) { @@ -93,9 +98,8 @@ class _ReaderWidgetState extends State } break; case AppLifecycleState.inactive: - break; case AppLifecycleState.paused: - controller?.stopImageStream().then((_) => controller?.dispose()); + controller?.dispose(); setState(() { _cameraOn = false; });