wu9007 / qrcode_scanner

🛠 Flutter QR code scanner plugin.
MIT License
357 stars 185 forks source link

Scan never ends #62

Closed HTMHell closed 2 years ago

HTMHell commented 4 years ago

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.

CellCS commented 4 years ago

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. 
ilyastuit commented 3 years ago

I got the same problem, you figured it out?

HTMHell commented 3 years ago

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.

ilyastuit commented 3 years ago

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.

lucaslannes commented 3 years ago

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