mintware-de / flutter_barcode_reader

A flutter plugin for reading 2D barcodes and QR codes.
MIT License
628 stars 463 forks source link

Barcode Scanner not reading Barcode #217

Closed mavericdesigner closed 4 years ago

mavericdesigner commented 4 years ago

We are currently experience an issue where the Barcode isn't actually scanned. The scanner seems not to detect the barcode. I've debugged the code up to

  static Future<ScanResult> _doScan(ScanOptions options) async {
    var config = proto.Configuration()
          ..useCamera = options.useCamera
          ..restrictFormat.addAll(options.restrictFormat)
          ..autoEnableFlash = options.autoEnableFlash
          ..strings.addAll(options.strings)
          ..android = (proto.AndroidConfiguration()
                ..useAutoFocus = options.android.useAutoFocus
                ..aspectTolerance = options.android.aspectTolerance
              /**/)
        /**/;
    var buffer = await _channel.invokeMethod('scan', config?.writeToBuffer());
    var tmpResult = proto.ScanResult.fromBuffer(buffer);
    return ScanResult(
      format: tmpResult.format,
      formatNote: tmpResult.formatNote,
      rawContent: tmpResult.rawContent,
      type: tmpResult.type,
    );
  }

useCamera=-1 unless I force it in the options:

int numberOfCameras = await BarcodeScanner.numberOfCameras;
            var options = ScanOptions(
                useCamera: numberOfCameras-2
            );

I don't know if it is part of the issue.

My config is as follows:

Screenshot 2020-04-20 at 14 45 59

Please inform me if I'm doing something stupid.

devtronic commented 4 years ago

Thanks for the details, I'll try to reproduce / fix the issue today. useCamera=-1 means "Use the default camera". This equals the behaviour pre 3.0.0

rpandey91 commented 4 years ago

I'm also facing the same issue, camera opens.. after scanning the QR, it doesn't returns the result. Behaviour is same on android and ios. barcode_scan version 3.0.3 Regards,

pablog9 commented 4 years ago

Same issue here, no errors, it just scans the code but exits back to the app without any result v3.0.0, previous version 2.0.2 works fine.

devtronic commented 4 years ago

I can't reproduce the problem. I compiled the example App as release and tested it both on iOS 13 and Android 9. @mavericdesigner: PDF 417 Is recognized really slow but I didn't find the reason for that. @rpandey91: The current version is 3.0.0

Can anyone reproduce the problem with the example app in this repo?

arne-kapell commented 4 years ago

Android: Same problem, but when using the example app everything works. I already faced the same problem in 3.0.0-dev.3 (maybe this helps)

Logcat: D/ViewRootImpl(15318): ViewPostImeInputStage ACTION_DOWN I/Timeline(15318): Timeline: Activity_launch_request id:de.devvillage.abipay time:1191053 D/PhoneWindow(15318): *FMB* installDecor mIsFloating : false D/PhoneWindow(15318): *FMB* installDecor flags : -2139029248 D/PhoneWindow(15318): *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null D/PhoneWindow(15318): *FMB* isFloatingMenuEnabled return false D/mali_winsys(15318): new_window_surface returns 0x3000, [480x800]-format:1 I/Timeline(15318): Timeline: Activity_idle id: android.os.BinderProxy@2df06e8e time:1191436 V/ActivityThread(15318): updateVisibility : ActivityRecord{2b5c8608 token=android.os.BinderProxy@12c9dfab {de.devvillage.abipay/de.devvillage.abipay.MainActivity}} show : false D/mali_winsys(15318): new_window_surface returns 0x3000, [480x800]-format:1 D/mali_winsys(15318): new_window_surface returns 0x3000, [480x800]-format:1 D/mali_winsys(15318): new_window_surface returns 0x3000, [480x800]-format:1 I/Timeline(15318): Timeline: Activity_idle id: android.os.BinderProxy@12c9dfab time:1195454 D/InputMethodManager(15318): windowDismissed mLockisused = false

popcos commented 4 years ago

Hi

  1. Cloning the repo and compile works fine ..
  2. Creating new flutter project , add library at pubspec.yaml works fine ...
  3. Migrating from version 2.0.2 to 3.0.0 doesn't work..

Resolving this after Replacing the Plugin Registry with FlutterEngine

  1. Deleting the GeneratedPluginRegistrant.java under android->app>src->main->java->io->flutter->plugins

  2. Add meta-data flutterEmbedding at AndroidManifest.xml

<meta-data android:name="flutterEmbedding" android:value="2" />

at the end of the file according a fresh flutter project.

image

Works fine now !

arne-kapell commented 4 years ago
3. Migrating from version 2.0.2 to 3.0.0 doesn't work..

Resolving this after Replacing the Plugin Registry with FlutterEngine

1. Deleting the GeneratedPluginRegistrant.java under android->app>src->main->java->io->flutter->plugins

2. Add meta-data flutterEmbedding at AndroidManifest.xml

<meta-data android:name="flutterEmbedding" android:value="2" />

at the end of the file according a fresh flutter project.

throws error during build: e: /home/user/projects/abipay/android/app/src/main/kotlin/de/devvillage/abipay/MainActivity.kt: (11, 44): Type mismatch: inferred type is MainActivity but FlutterEngine was expected

popcos commented 4 years ago

Yes.. thats right .... sorry i forgot this ... Replace the default the MainActivity.kt at app->src->main->kotlin with the following code that, its the default code of a fresh project.

Don't forget to change the first line with your package name

` package com.replacethis.with.your.package

import androidx.annotation.NonNull; import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.engine.FlutterEngine import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterActivity() { override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { GeneratedPluginRegistrant.registerWith(flutterEngine); } } ` image

arne-kapell commented 4 years ago

@popcos sorry, but this throws e: /home/user/projects/abipay/android/app/src/main/kotlin/de/devvillage/abipay/MainActivity.kt: (9, 40): Unresolved reference: nonnull

popcos commented 4 years ago

Did you migrate to Android X ?

arne-kapell commented 4 years ago

is there no other way?

popcos commented 4 years ago

is there no other way?

ask @devtronic

arne-kapell commented 4 years ago

wait, actually i did migrate to androidX (sorry for that @popcos )

sanuzzi commented 4 years ago

That's true, a new flutter app just works fine with the package. The problem is not the migration of barcode_reader itself, but an "old" flutter project with the 3.0.0 package version.

A newer flutter project is generated with what @popcos said:

I had to configure Kotlin too, and I moved the MainActivity inside kotlin folder. The configuration needed was:

In app/build.gradle:

And in build.gradle:

What was all, it's working for me on Android. I don't know why this is necessary, and what to do on iOS.

arne-kapell commented 4 years ago

Thanks for the help! I now just created a new app and copied all my files over. I guess it was the MainActivity.kt, heres the new one:

package

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() { }

..maybe this helps others

devtronic commented 4 years ago

Can anyone provide an example project in which the problem exists?

popcos commented 4 years ago

According to https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects Old Flutter projects need to be upgrade in order your be compatible with the plugin.

devtronic commented 4 years ago

@popcos thanks for the link. I'll update the upgrade guide.