mobile_scanner
mobile_scanner copied to clipboard
Allow Duplicates
What
- Hi, I want to ask, since this library provide to allow scan duplicate data, can i give timer for next scan? cause every time i hit api with allowduplicate true, it will always hit until i remove the code from the scanner Thank you
Would love this feature as well. I tried to work around it by stopping the camera after the scan, waiting for a specific amount of time and starting the camera again afterwards. Sadly this introduced many issues - sometimes camera didn't come back, sometimes I couldn't stop it, sometimes it says it is stopped already :(! If anyone has a working solution for this maybe let us know!
I did a simple workaround using a boolean to allow scans :
void _onDetect(Barcode barcode, MobileScannerArguments? args) {
if (canScan) {
canScan = false;
// ...
Future.delayed(const Duration(milliseconds: 500), () => canScan = true)
}
}
In my case the Future.delayed
was placed in a whenComplete
block after a Future
called in the if
block
(Just to be clear: the scanner will still detect your code and fire events but you will not handle them past your if
statement when canScan == false
)
This is now possible with version 3.0.0-beta.4. https://github.com/juliansteenbakker/mobile_scanner/blob/5ebc65e96e8de7224e3a7265d388a8d5d00ee3fd/lib/src/mobile_scanner_controller.dart#L66