mobile_scanner
mobile_scanner copied to clipboard
Unable to scan same qr again
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.
And yes when i turened allowDuplicates on it is pushing infinite screens on navigation stack.
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.
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:
- add a
key: Key(version.toString())
toMobileScanner
Widget (version
is aint version
state of my component starting at 0) -
cameraController.dispose();
before the.push
- add a
then
statement to thepush
with
setState(() {
version++;
cameraController = MobileScannerController();
}
to force a full reset of the controller AND the widget.
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.
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
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!
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.
Since there has been lots of updates, please check with latest version 3.0.0-beta.4 and comment if this issue still exists.