如何在Flutter中使用相机预览读取二维码

Vit*_*esh -1 flutter

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

  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)),
        )
      ],
    );
  }
Run Code Online (Sandbox Code Playgroud)

Flu*_*evs 5

这可以通过使用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;
  });
}
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

在此处输入图片说明

请找到回购

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