【问题标题】:Flutter - Barcode Scanner and ListViewFlutter - 条码扫描器和 ListView
【发布时间】:2020-11-11 09:23:35
【问题描述】:

我已经在 Flutter 中实现了条码扫描

依赖:

  barcode_scan: any

代码:

  Future _scanBarcode(BuildContext context) async {
    try {
      ScanResult scanResult = await BarcodeScanner.scan(options: ScanOptions(

      ));
      String query = scanResult.rawContent;
      print("Scanned Value : $query");
    } on PlatformException catch (e) {
      if (e.code == BarcodeScanner.cameraAccessDenied) {
        _showErrorSnackbar(context, 'The user did not grant the camera permission!');
      } else {
        _showErrorSnackbar(context, 'Unknown error: $e');
      }
    } catch (e) {
      _showErrorSnackbar(context, 'Unknown error: $e');
    }
  }

我想用 ListView 在 Activity 中打开一个条码扫描器(在屏幕的 50% 中)

如何将条形码扫描仪保持在屏幕的一半。

我想无限扫描并在另一半屏幕显示详细信息(在 ListView 中绑定每个扫描的项目。)

谁能给点提示?帮帮我?

【问题讨论】:

    标签: flutter barcode barcode-scanner flutter-listview


    【解决方案1】:

    我已经使用 scan_preview 包完成了。

    我所做的是:

      @override
      Widget build(BuildContext context) {
        double height = MediaQuery.of(context).size.height;
        return Scaffold(
            appBar: AppBar(
              title: Text("Barcode Scanner"),
              centerTitle: true,
            ),
            body: Column(
              children: [
                SizedBox(
                  width: double.infinity,
                  height: height/1.5,
                  child: ScanPreviewWidget(
                    onScanResult: (result) {
                      debugPrint('scan result: $result');
                      setState(() {
                        barcode = result;
                      });
                    },
                  ),
                ),
                SizedBox(height: 20),
                Center(child: Text(barcode))
              ],
            ));
      }
    

    【讨论】:

      猜你喜欢
      • 2021-06-18
      • 2019-01-04
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多