mobile_scanner icon indicating copy to clipboard operation
mobile_scanner copied to clipboard

Unable to scan same qr again

Open jayesh-maiyani opened this issue 2 years ago • 7 comments

What

  • The problem I'm having is that i'm sending the scanned result to another screen, but when i get back to the scanner by pressing back button of navigation it just simply won't scan the same qr. though it works fine with other new qr. issue.txt

Please help.

jayesh-maiyani avatar May 14 '22 04:05 jayesh-maiyani

And yes when i turened allowDuplicates on it is pushing infinite screens on navigation stack.

jayesh-maiyani avatar May 14 '22 04:05 jayesh-maiyani

same problem here, I temporary resolve it by using push (not pop navigate) the page to the scan page again, so the scan page will rebuild again.

bostaginting avatar May 18 '22 08:05 bostaginting

Same issue for me, I'am using push/pop navigation and i cant scan the same QR code after the pop.

My solution was to do:

  1. add a key: Key(version.toString()) to MobileScanner Widget (version is a int version state of my component starting at 0)
  2. cameraController.dispose(); before the .push
  3. add a then statement to the push with
            setState(() {
                version++;
                cameraController = MobileScannerController();
            }

to force a full reset of the controller AND the widget.

jvinai avatar May 20 '22 08:05 jvinai

You still need to set allowDuplicates to true, however you will manually need to restrict the navigator pushed with something like this:

                onDetect: (barcode, args) {
                  if (this.barcode != barcode.rawValue) {
                   this.barcode = barcode.rawValue;
                    // Push to new screen
                  }
                },

And when you pop back to this screen you need to set this.barcode to null or something else.

juliansteenbakker avatar May 23 '22 17:05 juliansteenbakker

Same issue for me, I'am using push/pop navigation and i cant scan the same QR code after the pop.

My solution was to do:

1. add a `key: Key(version.toString())` to `MobileScanner` Widget (`version` is a `int version` state of my component starting at 0)

2. `cameraController.dispose();` before the `.push`

3. add a `then` statement to the `push` with
            setState(() {
                version++;
                cameraController = MobileScannerController();
            }

to force a full reset of the controller AND the widget.

Hi, where did you initialize controlller ? because if I initialized it in initstate, camera is frozen on popping back. Thanks for answer @jvinai

hreso110100 avatar Jun 03 '22 10:06 hreso110100

I've got a solution for my problem: I was trying to navigate to a new page with data from a QR-Code, but in background when allowDublicates: true it was opening multiple Pages. With allowDublicates: false it was opening a Page once, but you were not able to scan this code again, which makes in production no sense.

So this is my solution like @juliansteenbakker already mentioned: After onDetect: I am navigating to an individual Page which returns a bool.

onDetect: (barcode, args) async {
        dynamic result;
        if (this.barcode != barcode.rawValue) {
          this.barcode = barcode.rawValue;
          try {
            await controller.stop();
            setState(() {
              final data = getID(barcode.rawValue);
                result = Navigator.pushNamed(
                    context, '/PupilCheck', arguments: {
                  'pupilID': data.pupilID,
                });
            });
          } on Exception catch (e) {
            print(e);
          };
          if (await result == true) {
            controller.start();
            isStarted = false;
           this.barcode = null;
          }
        }
      }
    ),

Hopefully it helps!

mofukommit avatar Jun 07 '22 09:06 mofukommit

There should be an integrated way to activate/deactivate the ability to rescan a qr-code when navigating, as well as an option to set a timer between rescans when a scan failed for example.

nomoruyi avatar Jul 27 '22 16:07 nomoruyi

Since there has been lots of updates, please check with latest version 3.0.0-beta.4 and comment if this issue still exists.

juliansteenbakker avatar Dec 13 '22 20:12 juliansteenbakker