Skip to content

How to set detection intervals ? #39

Answered by juliansteenbakker
utamori asked this question in Q&A
Discussion options

You must be logged in to vote

You can work with intervals, but something that is more suitable is maybe to check on duplicates.

An interval can be something like

  Timer? _timer; // Declared in your statefull class

// onDetect function of MobileScanner
    onDetect: (barcode, args) {
      if (_timer == null || !_timer!.isActive) {
        _timer = Timer(Duration(seconds: 2), () {});
        // do something
      }
  }

To check on duplicates you can do something like this:

String? barcode; // Declared in your statefull class

// onDetect function of MobileScanner
onDetect: (barcode, args) {
  if (this.barcode != barcode.rawValue) {
    // New barcode found !!
    setState(() {
      this.barcode = barcode.rawValue;
 …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@utamori
Comment options

Answer selected by utamori
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants