首页 > 解决方案 > 条码崩溃无错误

问题描述

我正在使用 qrCode 扫描仪制作应用程序,当我在 iphone 上打开应用程序并触摸 qrCode 扫描按钮时,它会自动关闭,甚至不打开相机。我在 pubspec.yaml 中使用了barcode_scan,代码是:

String qrResult = "Not yet Scanned";
    onPressed: () async {
                    String scaning = await BarcodeScanner.scan();
                    setState(() {
                      qrResult = scaning;
                    });
                  },

该应用程序是用颤振制作的

标签: flutterbarcode

解决方案


    scan() async {                                                 
   try {
         dynamic bar = await BarcodeScanner.scan();
       if(bar != null && bar.isNotEmpty){
          print(" scanning qrcode ------------------------ $barcode");
     setState(() {
       barcode = bar;
     });
    }} on PlatformException catch (e) {
     setState(() => this.barcode = '');
  
   } on FormatException{
  setState(() => this.barcode = '');
   } catch (e) {
  setState(() => this.barcode = '');
   }
 }

推荐阅读