Flutter barcode_scan unable to get a response

Viewed 5651

I'm using the barcode_scan package to get barcode information.

barcode_scan: ^3.0.1

I have a super simple test scenario set up like this:

ScanResult result = await BarcodeScanner.scan();
print(result.rawContent); 

I see the barcode scanner screen show up, and it appears to detect the barcode because as soon as I focus on the barcode it pauses and the closes the barcode scanner screen. however, it never reaches the line below print(result.rawContent); I'm not seeing any errors either. I've tried wrapping the whole thing in a try catch just to see, but it never entered the catch. It's like it just doesn't return anything from the await BarcodeScanner.scan() call and just aborts completely.

I'm not sure what I'm doing wrong here.

3 Answers

I meet the same issue on my existing project was created on old version of flutter, when I create new project with last version of flutter(1.12.x-pre) it is work find.

  • flutter(1.12.x-pre) down can use barcode_scan: ^2.x.x
  • flutter(1.12.x-pre) up can use barcode_scan: ^3.x.x

It is not bug, I just found new issue on barcode_scan.

Issue: https://github.com/mintware-de/flutter_barcode_reader/issues/261#issue-643704981

I'm a newer of flutter.

I solved downgrading barcode_scan from 3.0.1 to 2.0.0.

I hope it helps

In the barcode_scan Flutter package Getting Started section, there are a few setup steps that you have to follow (if you haven't done so already)

If you are testing this on an android device, try these following steps:

  1. you will need to add the camera permission App-level AndroidManifest.xml in the debug folder. In my test app, I placed it under <uses-permission android:name="android.permission.INTERNET"/>
  2. In the project-level build.gradle file, be sure to check the ext.kotlin_version is the same as the one listed, which at the time of writing is 1.3.61
  3. Check your app-level build.gradle as well to make sure it has the lines listed in the Getting Started Guide.
  4. Lastly (I know you already did this but), depend on the package in the pubspec.yaml file.

If you are testing this on an iOS device, try these following steps:

  1. Make sure to add the following code for camera usage description in the Info.plist file.
<dict>
    <!-- ... -->
    <key>NSCameraUsageDescription</key>
    <string>Camera permission is required for barcode scanning.</string>
    <!-- ... -->
</dict>

Source: https://pub.dev/packages/barcode_scan#-readme-tab-

Related