Julian Steenbakker
Committed by GitHub

Merge pull request #180 from yuchan2215/feature

add autoResume Option
@@ -55,7 +55,7 @@ class _MobileScannerState extends State<MobileScanner> @@ -55,7 +55,7 @@ class _MobileScannerState extends State<MobileScanner>
55 void didChangeAppLifecycleState(AppLifecycleState state) { 55 void didChangeAppLifecycleState(AppLifecycleState state) {
56 switch (state) { 56 switch (state) {
57 case AppLifecycleState.resumed: 57 case AppLifecycleState.resumed:
58 - if (!controller.isStarting) controller.start(); 58 + if (!controller.isStarting && controller.autoResume) controller.start();
59 break; 59 break;
60 case AppLifecycleState.inactive: 60 case AppLifecycleState.inactive:
61 case AppLifecycleState.paused: 61 case AppLifecycleState.paused:
@@ -53,6 +53,9 @@ class MobileScannerController { @@ -53,6 +53,9 @@ class MobileScannerController {
53 bool hasTorch = false; 53 bool hasTorch = false;
54 late StreamController<Barcode> barcodesController; 54 late StreamController<Barcode> barcodesController;
55 55
  56 + /// Whether to automatically resume the camera when the application is resumed
  57 + bool autoResume;
  58 +
56 Stream<Barcode> get barcodes => barcodesController.stream; 59 Stream<Barcode> get barcodes => barcodesController.stream;
57 60
58 MobileScannerController({ 61 MobileScannerController({
@@ -60,6 +63,7 @@ class MobileScannerController { @@ -60,6 +63,7 @@ class MobileScannerController {
60 this.ratio, 63 this.ratio,
61 this.torchEnabled, 64 this.torchEnabled,
62 this.formats, 65 this.formats,
  66 + this.autoResume = true,
63 }) { 67 }) {
64 // In case a new instance is created before calling dispose() 68 // In case a new instance is created before calling dispose()
65 if (_controllerHashcode != null) { 69 if (_controllerHashcode != null) {