Showing
2 changed files
with
10 additions
and
0 deletions
| @@ -64,6 +64,12 @@ class _MobileScannerState extends State<MobileScanner> | @@ -64,6 +64,12 @@ class _MobileScannerState extends State<MobileScanner> | ||
| 64 | 64 | ||
| 65 | /// Start the given [scanner]. | 65 | /// Start the given [scanner]. |
| 66 | void _startScanner(MobileScannerController scanner) { | 66 | void _startScanner(MobileScannerController scanner) { |
| 67 | + if (!_controller.autoStart) { | ||
| 68 | + debugPrint( | ||
| 69 | + 'mobile_scanner: not starting automatically because autoStart is set to false in the controller.', | ||
| 70 | + ); | ||
| 71 | + return; | ||
| 72 | + } | ||
| 67 | scanner.start().then((arguments) { | 73 | scanner.start().then((arguments) { |
| 68 | // ignore: deprecated_member_use_from_same_package | 74 | // ignore: deprecated_member_use_from_same_package |
| 69 | widget.onStart?.call(arguments); | 75 | widget.onStart?.call(arguments); |
| @@ -19,6 +19,7 @@ class MobileScannerController { | @@ -19,6 +19,7 @@ class MobileScannerController { | ||
| 19 | this.returnImage = false, | 19 | this.returnImage = false, |
| 20 | @Deprecated('Instead, use the result of calling `start()` to determine if permissions were granted.') | 20 | @Deprecated('Instead, use the result of calling `start()` to determine if permissions were granted.') |
| 21 | this.onPermissionSet, | 21 | this.onPermissionSet, |
| 22 | + this.autoStart = true, | ||
| 22 | }) { | 23 | }) { |
| 23 | // In case a new instance is created before calling dispose() | 24 | // In case a new instance is created before calling dispose() |
| 24 | if (controllerHashcode != null) { | 25 | if (controllerHashcode != null) { |
| @@ -64,6 +65,9 @@ class MobileScannerController { | @@ -64,6 +65,9 @@ class MobileScannerController { | ||
| 64 | /// [DetectionSpeed.normal] (which is the default value). | 65 | /// [DetectionSpeed.normal] (which is the default value). |
| 65 | final int detectionTimeoutMs; | 66 | final int detectionTimeoutMs; |
| 66 | 67 | ||
| 68 | + /// Automatically start the mobileScanner on initialization. | ||
| 69 | + final bool autoStart; | ||
| 70 | + | ||
| 67 | /// Sets the barcode stream | 71 | /// Sets the barcode stream |
| 68 | final StreamController<BarcodeCapture> _barcodesController = | 72 | final StreamController<BarcodeCapture> _barcodesController = |
| 69 | StreamController.broadcast(); | 73 | StreamController.broadcast(); |
-
Please register or login to post a comment