Julian Steenbakker
Committed by GitHub

Update lib/src/mobile_scanner.dart

Co-authored-by: Navaron Bracke <brackenavaron@gmail.com>
@@ -285,7 +285,23 @@ class _MobileScannerState extends State<MobileScanner> @@ -285,7 +285,23 @@ class _MobileScannerState extends State<MobileScanner>
285 } 285 }
286 286
287 Future<void> disposeMobileScanner() async { 287 Future<void> disposeMobileScanner() async {
  288 + Future<void> disposeMobileScanner() async {
  289 + if (widget.controller == null) {
  290 + WidgetsBinding.instance.removeObserver(this);
  291 + }
  292 +
288 await _subscription?.cancel(); 293 await _subscription?.cancel();
  294 + _subscription = null;
  295 +
  296 + if (controller.autoStart) {
  297 + await controller.stop();
  298 + }
  299 +
  300 + // Dispose default controller if not provided by user
  301 + if (widget.controller == null) {
  302 + await controller.dispose();
  303 + }
  304 + }
289 WidgetsBinding.instance.removeObserver(this); 305 WidgetsBinding.instance.removeObserver(this);
290 306
291 if (controller.autoStart) { 307 if (controller.autoStart) {