AmolGangadhare / flutter_barcode_scanner

Barcode scanner plugin for flutter. Supports barcode scanning for Android and iOS
https://pub.dev/packages/flutter_barcode_scanner
MIT License
380 stars 499 forks source link

Cooldown time #125

Closed eduardotq closed 4 years ago

eduardotq commented 4 years ago

Hi, would have some possibility to set a cooldown time in the continuous scan? It's because when I'm using it, sometime it scans too fast and register the same barcode more than one time. If you could set some cooldown time, would be nice. Thank you!

novembrea commented 4 years ago

I've also encountered this problem. You can enforce intervals between scans by transforming the stream, I'm pretty new to reactive programming but it does work as intended.

subscription = FlutterBarcodeScanner.getBarcodeStreamReceiver(
      '#FF0000',
      'CLOSE',
      true,
      ScanMode.BARCODE,
    ).transform(
      StreamTransformer.fromHandlers(
        handleData: (data, sink) {
          if (timer == null) {
            sink.add(data);

            // Set desirable interval in Duration.
            timer = Timer(Duration(seconds: 1), () {
              timer = null;
            });
          }
        },
      ),
    ).listen((barcode) {
      if ((barcode ?? '').isEmpty || barcode == '-1') {
        subscription.cancel();
        return;
      }
     // Do something with barcode
    });
eduardotq commented 4 years ago

I'm a newbie programmer, so I had no ideia how to solve this problem.. Thank you very much!

novembrea commented 4 years ago

Would be a good idea to close the issue if it's resolved for you. Cheers!

eduardotq commented 4 years ago

Sorry, I forgot

alperen23230 commented 3 years ago

Thank you for solution. It's work very well 👍🏾