mobile_scanner icon indicating copy to clipboard operation
mobile_scanner copied to clipboard

Allow Duplicates

Open krisnachy opened this issue 2 years ago • 2 comments

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

krisnachy avatar Aug 29 '22 10:08 krisnachy

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!

novas1r1 avatar Oct 07 '22 09:10 novas1r1

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)

ArthurVinbeau avatar Oct 13 '22 09:10 ArthurVinbeau

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

juliansteenbakker avatar Dec 13 '22 16:12 juliansteenbakker