简体   繁体   English

Flutter 条码扫描无法得到响应

[英]Flutter barcode_scan unable to get a response

I'm using the barcode_scan package to get barcode information.我正在使用barcode_scan package 来获取条形码信息。

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);但是,它永远不会到达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.我已经尝试将整个东西包装在一个 try catch 中只是为了看看,但它从未进入 catch 中。 It's like it just doesn't return anything from the await BarcodeScanner.scan() call and just aborts completely.就好像它没有从await BarcodeScanner.scan()调用中返回任何内容,只是完全中止。

I'm not sure what I'm doing wrong here.我不确定我在这里做错了什么。

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)创建新项目时,它是工作找到的。

  • flutter(1.12.x-pre) down can use barcode_scan: ^2.xx flutter(1.12.x-pre) down 可以使用barcode_scan: ^2.xx
  • flutter(1.12.x-pre) up can use barcode_scan: ^3.xx flutter(1.12.x-pre) up 可以使用barcode_scan: ^3.xx

It is not bug, I just found new issue on barcode_scan.这不是错误,我刚刚在barcode_scan 上发现了新问题。

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

I'm a newer of flutter.我是 flutter 的更新者。

I solved downgrading barcode_scan from 3.0.1 to 2.0.0 .我解决了将barcode_scan3.0.1降级到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)在barcode_scan Flutter package 入门部分中,您必须遵循一些设置步骤(如果您还没有这样做的话)

If you are testing this on an android device, try these following steps:如果您在android设备上进行测试,请尝试以下步骤:

  1. you will need to add the camera permission App-level AndroidManifest.xml in the debug folder.您需要在调试文件夹中添加相机权限 App 级 AndroidManifest.xml。 In my test app, I placed it under <uses-permission android:name="android.permission.INTERNET"/>在我的测试应用程序中,我将它放在<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项目级 build.gradle 文件中,请务必检查 ext.kotlin_version 是否与列出的相同,在撰写本文时为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.检查您的应用程序级 build.gradle 以确保它具有入门指南中列出的行。
  4. Lastly (I know you already did this but), depend on the package in the pubspec.yaml file.最后(我知道您已经这样做了,但是),取决于 pubspec.yaml 文件中的 package。

If you are testing this on an iOS device, try these following steps:如果您在iOS设备上对此进行测试,请尝试以下步骤:

  1. Make sure to add the following code for camera usage description in the Info.plist file.确保在 Info.plist 文件中添加以下代码用于相机使用说明。
<dict>
    <!-- ... -->
    <key>NSCameraUsageDescription</key>
    <string>Camera permission is required for barcode scanning.</string>
    <!-- ... -->
</dict>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM