[TOC]
二维码扫描 同时支持 Android&IOS
扫描效果
android
IOS
dependencies:
flutter_plugin_qrcode: ^1.0.1
##导入头文件
import 'package:flutter_plugin_qrcode/flutter_plugin_qrcode.dart';
Future<void> getQrcodeState() async {
String qrcode;
try {
qrcode = await FlutterPluginQrcode.getQRCode;
} on PlatformException {
qrcode = 'Failed to get platform version.';
}
if (!mounted) return;
//获取到扫描的结果进行页面更新
setState(() {
_qrcode = qrcode;
});
}
####1,记得在AndroidManifest.xml 添加访问相机的权限 动态申请权限
<uses-permission android:name="android.permission.CAMERA" />
<!-- 相机 -->
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能访问相机</string>