Julian Steenbakker

feat: add autoStart parameter

... ... @@ -64,6 +64,12 @@ class _MobileScannerState extends State<MobileScanner>
/// Start the given [scanner].
void _startScanner(MobileScannerController scanner) {
if (!_controller.autoStart) {
debugPrint(
'mobile_scanner: not starting automatically because autoStart is set to false in the controller.',
);
return;
}
scanner.start().then((arguments) {
// ignore: deprecated_member_use_from_same_package
widget.onStart?.call(arguments);
... ...
... ... @@ -19,6 +19,7 @@ class MobileScannerController {
this.returnImage = false,
@Deprecated('Instead, use the result of calling `start()` to determine if permissions were granted.')
this.onPermissionSet,
this.autoStart = true,
}) {
// In case a new instance is created before calling dispose()
if (controllerHashcode != null) {
... ... @@ -64,6 +65,9 @@ class MobileScannerController {
/// [DetectionSpeed.normal] (which is the default value).
final int detectionTimeoutMs;
/// Automatically start the mobileScanner on initialization.
final bool autoStart;
/// Sets the barcode stream
final StreamController<BarcodeCapture> _barcodesController =
StreamController.broadcast();
... ...