首页 > 解决方案 > 我如何在颤振中读取带有相机预览的二维码

问题描述

她是我用于显示相机的代码,但问题是我为扫描二维码所做的工作。请帮我。

  Widget camera() {
    return Stack(
      alignment: Alignment.center,
      children: <Widget>[
        new Container(
          decoration: BoxDecoration(
              border: Border.all(color: Colors.myColor, width: 1.0)),
          padding: EdgeInsets.all(4.0),
          child: new SizedBox(
            height: MediaQuery.of(context).size.height / 1.5,
            width: MediaQuery.of(context).size.width / 1.5,
            child: new AspectRatio(
              aspectRatio: controller.value.aspectRatio,
              child: CameraPreview(controller),
            ),
          ),
        ),
        new Container(
          height: 100.0,
          width: 100.0,
          decoration: BoxDecoration(
              border: Border.all(color: Colors.myColor, width: 2.0)),
        )
      ],
    );
  }

标签: flutter

解决方案


这可以通过使用颤振条形码扫描依赖项来完成。

Future _openQRScanner() async {
try {
  // Below code will open camera preview and return result after qr scan 
  String _content = await BarcodeScanner.scan();
  setState(() => this._content = _content);
} on PlatformException catch (e) {
  if (e.code == BarcodeScanner.CameraAccessDenied) {
    showSnackBar('Please grant camera permission!');
    setState(() {
      this._content = null;
    });
  } else {
    showSnackBar('Error: $e');
    setState(() {
      this._content = null;
    });
  }
} on FormatException {
  showSnackBar('User pressed "back" button before scanning');
  setState(() {
    this._content = null;
  });
} catch (e) {
  showSnackBar('Error: $e');
  setState(() {
    this._content = null;
  });
}
}

在此处输入图像描述

在此处输入图像描述

请找到回购

如果你想看看 Flutter,你可以在我们公司的 Github页面上找到一些很好的例子。另外,您可以查看我们公司的页面FlutterDevs


推荐阅读