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> @@ -271,7 +271,7 @@ class _MobileScannerState extends State<MobileScanner>
271 // } 271 // }
272 // } 272 // }
273 273
274 - if (widget.onDetect != null) { 274 + if (widget.controller == null) {
275 WidgetsBinding.instance.addObserver(this); 275 WidgetsBinding.instance.addObserver(this);
276 _subscription = controller.barcodes.listen( 276 _subscription = controller.barcodes.listen(
277 widget.onDetect, 277 widget.onDetect,
@@ -285,7 +285,7 @@ class _MobileScannerState extends State<MobileScanner> @@ -285,7 +285,7 @@ class _MobileScannerState extends State<MobileScanner>
285 } 285 }
286 286
287 Future<void> disposeMobileScanner() async { 287 Future<void> disposeMobileScanner() async {
288 - if (widget.onDetect != null) { 288 + if (widget.controller == null) {
289 WidgetsBinding.instance.removeObserver(this); 289 WidgetsBinding.instance.removeObserver(this);
290 } 290 }
291 291
@@ -317,7 +317,7 @@ class _MobileScannerState extends State<MobileScanner> @@ -317,7 +317,7 @@ class _MobileScannerState extends State<MobileScanner>
317 317
318 @override 318 @override
319 void didChangeAppLifecycleState(AppLifecycleState state) { 319 void didChangeAppLifecycleState(AppLifecycleState state) {
320 - if (widget.controller != null || !controller.value.hasCameraPermission) { 320 + if (!controller.value.hasCameraPermission) {
321 return; 321 return;
322 } 322 }
323 323
@@ -327,15 +327,8 @@ class _MobileScannerState extends State<MobileScanner> @@ -327,15 +327,8 @@ class _MobileScannerState extends State<MobileScanner>
327 case AppLifecycleState.paused: 327 case AppLifecycleState.paused:
328 return; 328 return;
329 case AppLifecycleState.resumed: 329 case AppLifecycleState.resumed:
330 - _subscription = controller.barcodes.listen(  
331 - widget.onDetect,  
332 - onError: widget.onDetectError,  
333 - cancelOnError: false,  
334 - );  
335 -  
336 unawaited(controller.start()); 330 unawaited(controller.start());
337 case AppLifecycleState.inactive: 331 case AppLifecycleState.inactive:
338 - unawaited(_subscription?.cancel());  
339 unawaited(controller.stop()); 332 unawaited(controller.stop());
340 } 333 }
341 } 334 }