rmtmckenzie/flutter_qr_mobile_vision

Restrict duplicate barcode scanning

sudheeshde opened this issue · 5 comments

Hi,

Thanks for this awesome library. Is there any way to restrict the duplicate barcode scanning inbuilt in this library?

Do you mean that the qrCodeCallback is being called more than once? I considered limiting that when creating the library, but decided against it as it is very easy to handle that in the code where you're receiving it - you can either call stop as soon as you receive the first barcode or keep a variable with the last received and ignore anything else. If you mean something else could you clarify?

Thanks for the reply. Yes, I meant the qrCodeCallback. I've handled it by checking against a list with the last scanned items. I was just curious whether the library has an inbuilt option for this. Anyway thanks for your clarification.

Hi @rmtmckenzie,

I have one more query that needs a clarification:

When I'm scanning a barcode repeatedly, sometimes it detects correctly sometimes shows different results, it may be off with just one digit if my barcode is an IMEI number with 14 or 15 digits. Is there any way we can control this behavior?
Please check below link to see what's happening while scanning:
https://1drv.ms/v/s!AgZeh_DlKYsUjZw2mdPKPuWlGwNLQw?e=03QaVO

Unfortunately that's a limitation of the underlying scanning libraries & the camera. Bumping up the resolution might help, but I think it still won't be 100% reliable. Unfortunately that's not something that's super well supported with the easy-to-use code that handles rotation etc at the moment, but you could theoretically use the underlying QrMobileVision class. Also, scanning from another device's screen is always going to be less reliable than from something like paper - the glare + pixels mess with the algorithm, so it might be worth checking on a printed item if that's what you'll be using in practice.

If it is going to be digital and if you have any control over the device where the barcode is displayed, I'd recommend seeing if you can use QR codes instead of barcodes as they're much more robust in a digital scanning context, especially with extra error correction turned on.

here is mine:

 bool _screenOpened = false;

qrCodeCallback: (code) {
          if (!_screenOpened) {
            _screenOpened = true;
            if (isEMT10Format(code.toString())) {
              Navigator.push(
                context,
                CupertinoPageRoute(
                    builder: (context) => VerifierSuccessScreen(
                          screenClose: _screenWasClosed,
                        )),
              );
              context
                  .read<CertusBloc>()
                  .add(CodeVerification(dataQr: code.toString()));
            } else {
              print('Scanned QR code does not contain EMT 1.0 format');
            }
          }
        },

 void _screenWasClosed() {
    _screenOpened = false;
  }

and when back to scan screen, just invoke this:

 @override
 Widget build(BuildContext context) {
   return WillPopScope(
     onWillPop: () {
       Navigator.pop(context, false);
       screenClose();
       return Future.value(true);
     },