Julian Steenbakker

fix: remove unnecessary stream pause on inactive, only use observer when no controller is passed

... ... @@ -271,7 +271,7 @@ class _MobileScannerState extends State<MobileScanner>
// }
// }
if (widget.onDetect != null) {
if (widget.controller == null) {
WidgetsBinding.instance.addObserver(this);
_subscription = controller.barcodes.listen(
widget.onDetect,
... ... @@ -285,7 +285,7 @@ class _MobileScannerState extends State<MobileScanner>
}
Future<void> disposeMobileScanner() async {
if (widget.onDetect != null) {
if (widget.controller == null) {
WidgetsBinding.instance.removeObserver(this);
}
... ... @@ -317,7 +317,7 @@ class _MobileScannerState extends State<MobileScanner>
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (widget.controller != null || !controller.value.hasCameraPermission) {
if (!controller.value.hasCameraPermission) {
return;
}
... ... @@ -327,15 +327,8 @@ class _MobileScannerState extends State<MobileScanner>
case AppLifecycleState.paused:
return;
case AppLifecycleState.resumed:
_subscription = controller.barcodes.listen(
widget.onDetect,
onError: widget.onDetectError,
cancelOnError: false,
);
unawaited(controller.start());
case AppLifecycleState.inactive:
unawaited(_subscription?.cancel());
unawaited(controller.stop());
}
}
... ...