Showing
3 changed files
with
15 additions
and
33 deletions
| @@ -25,23 +25,17 @@ class _BarcodeListScannerWithControllerState | @@ -25,23 +25,17 @@ class _BarcodeListScannerWithControllerState | ||
| 25 | ); | 25 | ); |
| 26 | 26 | ||
| 27 | bool isStarted = true; | 27 | bool isStarted = true; |
| 28 | + MobileScannerException? exception; | ||
| 28 | 29 | ||
| 29 | void _startOrStop() { | 30 | void _startOrStop() { |
| 30 | if (isStarted) { | 31 | if (isStarted) { |
| 31 | controller.stop(); | 32 | controller.stop(); |
| 32 | } else { | 33 | } else { |
| 33 | controller.start().catchError((error) { | 34 | controller.start().catchError((error) { |
| 34 | - final exception = error as MobileScannerException; | ||
| 35 | - | ||
| 36 | - switch (exception.errorCode) { | ||
| 37 | - case MobileScannerErrorCode.controllerUninitialized: | ||
| 38 | - break; // This error code is not used by `start()`. | ||
| 39 | - case MobileScannerErrorCode.genericError: | ||
| 40 | - debugPrint('Scanner failed to start'); | ||
| 41 | - break; | ||
| 42 | - case MobileScannerErrorCode.permissionDenied: | ||
| 43 | - debugPrint('Camera permission denied'); | ||
| 44 | - break; | 35 | + if (mounted) { |
| 36 | + setState(() { | ||
| 37 | + exception = error as MobileScannerException; | ||
| 38 | + }); | ||
| 45 | } | 39 | } |
| 46 | }); | 40 | }); |
| 47 | } | 41 | } |
| @@ -25,23 +25,17 @@ class _BarcodeScannerWithControllerState | @@ -25,23 +25,17 @@ class _BarcodeScannerWithControllerState | ||
| 25 | ); | 25 | ); |
| 26 | 26 | ||
| 27 | bool isStarted = true; | 27 | bool isStarted = true; |
| 28 | + MobileScannerException? exception; | ||
| 28 | 29 | ||
| 29 | void _startOrStop() { | 30 | void _startOrStop() { |
| 30 | if (isStarted) { | 31 | if (isStarted) { |
| 31 | controller.stop(); | 32 | controller.stop(); |
| 32 | } else { | 33 | } else { |
| 33 | controller.start().catchError((error) { | 34 | controller.start().catchError((error) { |
| 34 | - final exception = error as MobileScannerException; | ||
| 35 | - | ||
| 36 | - switch (exception.errorCode) { | ||
| 37 | - case MobileScannerErrorCode.controllerUninitialized: | ||
| 38 | - break; // This error code is not used by `start()`. | ||
| 39 | - case MobileScannerErrorCode.genericError: | ||
| 40 | - debugPrint('Scanner failed to start'); | ||
| 41 | - break; | ||
| 42 | - case MobileScannerErrorCode.permissionDenied: | ||
| 43 | - debugPrint('Camera permission denied'); | ||
| 44 | - break; | 35 | + if (mounted) { |
| 36 | + setState(() { | ||
| 37 | + exception = error as MobileScannerException; | ||
| 38 | + }); | ||
| 45 | } | 39 | } |
| 46 | }); | 40 | }); |
| 47 | } | 41 | } |
| @@ -27,23 +27,17 @@ class _BarcodeScannerReturningImageState | @@ -27,23 +27,17 @@ class _BarcodeScannerReturningImageState | ||
| 27 | ); | 27 | ); |
| 28 | 28 | ||
| 29 | bool isStarted = true; | 29 | bool isStarted = true; |
| 30 | + MobileScannerException? exception; | ||
| 30 | 31 | ||
| 31 | void _startOrStop() { | 32 | void _startOrStop() { |
| 32 | if (isStarted) { | 33 | if (isStarted) { |
| 33 | controller.stop(); | 34 | controller.stop(); |
| 34 | } else { | 35 | } else { |
| 35 | controller.start().catchError((error) { | 36 | controller.start().catchError((error) { |
| 36 | - final exception = error as MobileScannerException; | ||
| 37 | - | ||
| 38 | - switch (exception.errorCode) { | ||
| 39 | - case MobileScannerErrorCode.controllerUninitialized: | ||
| 40 | - break; // This error code is not used by `start()`. | ||
| 41 | - case MobileScannerErrorCode.genericError: | ||
| 42 | - debugPrint('Scanner failed to start'); | ||
| 43 | - break; | ||
| 44 | - case MobileScannerErrorCode.permissionDenied: | ||
| 45 | - debugPrint('Camera permission denied'); | ||
| 46 | - break; | 37 | + if (mounted) { |
| 38 | + setState(() { | ||
| 39 | + exception = error as MobileScannerException; | ||
| 40 | + }); | ||
| 47 | } | 41 | } |
| 48 | }); | 42 | }); |
| 49 | } | 43 | } |
-
Please register or login to post a comment