【问题标题】:Flutter Barcode_scan plugin crashing App?Flutter Barcode_scan 插件崩溃 App?
【发布时间】:2019-08-15 10:55:43
【问题描述】:

只要我点击相机按钮,应用就会崩溃。

它也没有要求任何许可。

我在清单中也包含了活动文件

这是我正在使用的代码,我正在使用的插件是barcode_scan:

即使搜索了很多,我也无法解决问题。 我们将不胜感激。

class _AuditPage extends State<AuditPage>{
 String result = "Scan The Barcode!";


 Future _scanQR() async{
    try{
      String qrCode = await BarcodeScanner.scan();
      setState(() {
        result = qrCode;
      });
    }on PlatformException catch (ex){
      if(ex.code==BarcodeScanner.CameraAccessDenied){
        setState(() {
          result="Camera Permission Was Denied";
        });
      }else{
        setState(() {
          result="Unknown Error $ex!";
        });
      }
    } on FormatException {
      setState(() {
        result = "You Pressed The Back Button Before Scanning";
      });
    } catch (ex){
      setState(() {
          result="Unknown Error $ex!";
        });
    }
 }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
       resizeToAvoidBottomPadding: false,
      appBar: AppBar(
        title: Text("Bhaifi"),
      ),
      drawer: DrawerPage(),
      body: Center(
        child:Text(
          result,
        ),
      ), 
        floatingActionButton:FloatingActionButton.extended(
          icon: Icon(Icons.camera_alt),
          label: Text("Scan"),
          onPressed: _scanQR,
        ),
      floatingActionButtonLocation:FloatingActionButtonLocation.centerFloat,
    );
  }


}

【问题讨论】:

  • 你想看看AndroidX问题:我有类似的情况,你可以从这篇文章中获取一些代码:stackoverflow.com/questions/55223002/…不是解决方案或更新,而是我在原帖中的故障排除;希望对你有帮助
  • 谢谢,但不工作
  • 尝试使用“旧的”:barcode_scan: ^0.0.8 ,如果不工作尝试不使用“^”:只需“barcode_scan: 0.0.8”
  • 不要指定barcode_scan的版本,它会为你添加合适的版本。

标签: android dart flutter barcode


【解决方案1】:

您可能没有在 AndroidManifest.xml 文件夹中添加依赖项,我遇到了同样的问题,只需修改 scanQR() 函数即可。

试试这个:

Future scanQR() async {
    try {
      String barcode;
      await BarcodeScanner.scan().then((onValue) {
        setState(() {
          barcode = onValue.toString();
        });
      }).catchError((onError) {
        print(onError);
      });
      setState(() => this.barcode = barcode);
    } on PlatformException catch (e) {
      if (e.code == BarcodeScanner.CameraAccessDenied) {
        setState(() {
          this.barcode = 'camera permission not granted!';
        });
      } else {
        setState(() => this.barcode = 'Unknown error: $e');
      }
    } on FormatException {
      setState(() => this.barcode = '(User returned)');
    } catch (e) {
      setState(() => this.barcode = 'Unknown error: $e');
    }
}

【讨论】:

    猜你喜欢
    • 2018-09-24
    • 2020-07-22
    • 2022-06-13
    • 1970-01-01
    • 2019-05-02
    • 2020-06-24
    • 2020-04-01
    • 2021-05-27
    • 2020-01-31
    相关资源
    最近更新 更多