Browse Source

fixed camera lifecycle issues

pull/38/head
Khoren Markosyan 2 years ago
parent
commit
589c852812
  1. 8
      lib/src/ui/reader_widget.dart

8
lib/src/ui/reader_widget.dart

@ -86,6 +86,11 @@ class _ReaderWidgetState extends State<ReaderWidget>
@override @override
void didChangeAppLifecycleState(AppLifecycleState state) { void didChangeAppLifecycleState(AppLifecycleState state) {
final CameraController? cameraController = controller;
if (cameraController == null || !cameraController.value.isInitialized) {
return;
}
switch (state) { switch (state) {
case AppLifecycleState.resumed: case AppLifecycleState.resumed:
if (cameras.isNotEmpty && !_cameraOn) { if (cameras.isNotEmpty && !_cameraOn) {
@ -93,9 +98,8 @@ class _ReaderWidgetState extends State<ReaderWidget>
} }
break; break;
case AppLifecycleState.inactive: case AppLifecycleState.inactive:
break;
case AppLifecycleState.paused: case AppLifecycleState.paused:
controller?.stopImageStream().then((_) => controller?.dispose()); controller?.dispose();
setState(() { setState(() {
_cameraOn = false; _cameraOn = false;
}); });

Loading…
Cancel
Save