juliansteenbakker / mobile_scanner

A universal scanner for Flutter based on MLKit. Uses CameraX on Android and AVFoundation on iOS.
BSD 3-Clause "New" or "Revised" License
807 stars 470 forks source link

Android 14 ERROR #1124

Open LorenzoVianello opened 1 month ago

LorenzoVianello commented 1 month ago

I'm developing an app which requires to scan a QR code to proceed. I switched from qr_code_scanner due to maintenance issues.

Flutter doctor output

foo@bar:~$ flutter doctor run
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.22.2, on Microsoft Windows [Versione 10.0.19045.4529], locale it-IT)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.3)
[√] Android Studio (version 2023.1)
[√] VS Code (version 1.91.1)
[√] Connected device (1 available)
[√] Network resources

• No issues found!

Code snipped

void onInit() async {
    super.onInit();
    WidgetsBinding.instance.addObserver(this);
    await initBarcodeScanner();
  }

  void onClose() async {
    super.onClose();
    WidgetsBinding.instance.removeObserver(this);
    await mobileScannerController.stop();
  }

  Future<void> initBarcodeScanner() async {
    if (await checkPermissions()) {
      WidgetsBinding.instance.addObserver(this);
      mobileScannerController.barcodes.listen(analyze);
      unawaited(
          mobileScannerController.start(cameraDirection: CameraFacing.back));
      barcodeInitialized.value = true;
      return;
    }
    barcodeInitialized.value = false;
  }

  void analyze(BarcodeCapture dataCaught) {
    for (Barcode barcode in dataCaught.barcodes) {
      String data = String.fromCharCodes(barcode.rawBytes?.toList() ?? []);
      debugPrint("Data: $data");
      if (QR.isValidRawData(data) && !_analyizingData.value) {
        _analyizingData.value = true;
        QR? qrCode = QR.fromCameraScan(data);
        if (qrCode == null) {
          _analyizingData.value = false;
          return;
        }
        back(result: qrCode);
      }
    }
  }

Provided code is fully working with 8 <= Android <= 13

When trying to scan QR code with Android 14 nothing happens, but with a lower version, works like a charm

Any idea why?

navaronbracke commented 1 month ago

This seems eerily similar to #1116, does this repro on Samsung devices or on other devices that use Android 14 as well?

Do these devices support YUV_420 as image format?