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)),
)
],
);
}
解决方案
这可以通过使用颤振条形码扫描依赖项来完成。
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。
推荐阅读
- java - 有没有办法在运行时访问和修改 Eclipse 插件的源代码?
- java - 无需遍历所有像素即可替换图像中的颜色
- java - java是否可以在数组中插入算术运算符(+ - / *)?
- laravel - 在新的 laravel 文件中执行“npm run”时出错 - 找不到模块 npm-cli.js
- html - 使用 %userprofile% 的数据源 iMacro
- javascript - 使用 javascript SDK 从 facebook graph api 获取个人资料图片
- kubernetes - Kubernetes 仪表板(Web UI)不工作
- python - 用于迁移学习的 Keras input_tensor 形状
- java - Jsoup getElementsByAttributeValueMatching 不起作用
- c++ - 以两个 std::vector 和一个常量作为参数的 std::transform