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
818 stars 476 forks source link

MobileScanner Widget is not showing the Preview. #1119

Open arnabonetraker opened 2 months ago

arnabonetraker commented 2 months ago

I've noticed that the MobileScanner widget occasionally stops displaying the camera preview until I restart my app. No error log was thrown so I am out of the loop. I am using the example method to start the camera using the WidgetsBindingObserver . It looks like this could be related to these issues -

605

589

976

Even after the camera preview was turned off, it continued to scan for me. If you watch the video, you will notice toast notifications appear, indicating that it detected a barcode but did not show a camera preview.

https://github.com/juliansteenbakker/mobile_scanner/assets/111729204/f165f21a-78f1-4ccb-a615-82d3c3f64d6f

mobile_scanner: ^5.1.1

Flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.22.2, on macOS 14.5 23F79 darwin-x64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.91.0)
[✓] Connected device (2 available)
[✓] Network resources

• No issues found!

Intitalization code:


  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
    _subscription = mobileScannerController.barcodes.listen(_handleBarcode);
    unawaited(mobileScannerController.start());
    }
    \\\\\\

    Stack(
         children: [
                MobileScanner(
                  controller: mobileScannerController,
                ),
                ScanOverlay(height: 2, width: width, color: Colors.green),
              ],
            )

      \\\\\

  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    unawaited(_subscription?.cancel());
    _subscription = null;
    mobileScannerController.dispose();
    super.dispose();

  }
erf commented 1 month ago

You should call super.dispose before controller.dispose(); according to the README.md

arnabonetraker commented 1 month ago

You should call super.dispose before controller.dispose(); according to the README.md

That does not appear to be the root cause of the problem. But I will modify and observe. As per as flutters documentation for dispose() method Implementations of this method should end with a call to the inherited method, as in super. dispose().

navaronbracke commented 3 weeks ago

Does this device require the NV21 image format?

arnabmactavish commented 2 weeks ago

Does this device require the NV21 image format?

I am not sure. This was from Oneplus Nord 2. But I have seen similar behaviour from my iPhone 10 as well.

navaronbracke commented 2 weeks ago

For your Oneplus Nord 2, does it support the YUV 420 format? If not, then NV21 would be required for that device.

For the iPhone, I'm not sure why it happens.

arnabmactavish commented 2 weeks ago

For your Oneplus Nord 2, does it support the YUV 420 format? If not, then NV21 would be required for that device.

For the iPhone, I'm not sure why it happens.

It supports YUV420.