juliuscanute / qr_code_scanner

QR Code Scanner for Flutter
BSD 2-Clause "Simplified" License
999 stars 759 forks source link

[BUG] qr_code_scanner 1.0 - iOS No barcode scanner found #557

Closed Dooks123 closed 2 years ago

Dooks123 commented 2 years ago

Describe the bug in the onQrViewCreated function I have the following:

void _onQrViewCreated(QRViewController controller) async {
  qrViewController = controller;
  await controller.resumeCamera(); //<---- Breaks here
  controller.scannedDataStream.listen(_onQrDataReceived);
}

I get the following Exception:

Exception has occurred CameraException (CameraException(404, No barcode scanner found))

Flutter information

[✓] Flutter (Channel stable, 3.0.2, on macOS 12.2.1 21D62 darwin-arm, locale
    en-ZA)
    • Flutter version 3.0.2 at /Users/XXX/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision cd41fdd495 (4 days ago), 2022-06-08 09:52:13 -0700
    • Engine revision f15f824b57
    • Dart version 2.17.3
    • DevTools version 2.12.2

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from:
      https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK
      components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup
      for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (not installed)
    • Android Studio not found; download from
      https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup
      for detailed instructions).

[✓] VS Code (version 1.67.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.42.0

[✓] Connected device (3 available)
    • XXX iPhone (mobile) • 8e74...269 • ios            • iOS 15.5 19F77
    • macOS (desktop)          • macos                                    • darwin-arm64   • macOS 12.2.1 21D62 darwin-arm
    • Chrome (web)             • chrome                                   • web-javascript • Google Chrome 102.0.5005.61

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 2 categories.

Device (please complete the following information):

Dooks123 commented 2 years ago

Nevermind, I fixed it. Now works on all Android and iOS:

void _onQrViewCreated(QRViewController controller) async {
  qrViewController = controller;
  if (Platform.isAndroid) {
    await controller.resumeCamera();
  }

  controller.scannedDataStream.listen(_onQrDataReceived);
}

@override
void reassemble() {
  if (Platform.isIOS) {
    qrViewController!.resumeCamera();
  }

  super.reassemble();
}
YouriB83 commented 1 year ago

Thanks @Dooks123 - This solution worked for me. 👍