qrcode_scanner icon indicating copy to clipboard operation
qrcode_scanner copied to clipboard

Scan never ends

Open HTMHell opened this issue 4 years ago • 5 comments

If I use scanPath or scanBytes to scan an image, and the image doesn't have a barcode, the code keeps waiting instead of returning null or throwing an exception or anything like it.

For example:

String path = '/path/to/my/image.jpg';
print('scanning barcode...');
String barcode = await scanner.scanPath(path);
print('done');

Will print "done" only if the image has a barcode. If not, "done" will never get executed and the code will keep on waiting to scanner.scanPath to finish. No exceptions are thrown.

  • Tested on an Android device

HTMHell avatar Jun 20 '20 19:06 HTMHell

This also does not work, no exception.

  static Future<String> decodeQRByData(Uint8List databytes) async {
    String barcode = "";
    try {
      await scanner
          .scanBytes(databytes)
          .then((value) => barcode = value)
          .catchError((e) {
        return barcode;
      });
    } catch (e) {}
    return barcode;
  }
I/flutter (30105): ------------
W/System.err(30105): com.google.zxing.NotFoundException
W/System  (30105): A resource failed to call close. 
I/chatty  (30105): uid=10134(com.example.app) FinalizerDaemon identical 2 lines
W/System  (30105): A resource failed to call close. 

CellCS avatar Aug 05 '20 02:08 CellCS

I got the same problem, you figured it out?

ilyastuit avatar Nov 23 '20 11:11 ilyastuit

I got the same problem, you figured it out?

Not really. As a workaround you can set timeout for the future method:

String barcode = await scanner
        .scanPath(path)
        .timeout(Duration(seconds: 2));

and you should catch the timeout exception, or pass onTimeout argument to timeout method.

HTMHell avatar Dec 14 '20 19:12 HTMHell

I got the same problem, you figured it out?

Not really. As a workaround you can set timeout for the future method:

String barcode = await scanner
        .scanPath(path)
        .timeout(Duration(seconds: 2));

and you should catch the timeout exception, or pass onTimeout argument to timeout method.

Thank you for response. However I decided not to use image scanning, I used only the camera.

ilyastuit avatar Dec 15 '20 05:12 ilyastuit

Folks, i made a pull request to allow catching this error. Check this out #92 :)

lucaslannes avatar Jan 21 '21 18:01 lucaslannes