Flutter 发布模式判断
//发布模式
const bool kReleaseMode = bool.fromEnvironment('dart.vm.product')
空值处理
// User below
title ??= "Title";
// instead of
if (title == null) {
title = "Title";
}
flutter 图片拍摄
插件:
https://pub.dev/packages/permission_handler
await Permission.camera.request().isGranted //获取拍照权限
https://pub.dev/packages/image_picker
final pickedFile = await picker.getImage(
source: ImageSource.camera,//开启摄像头
maxWidth: 600.w,//图片宽高
maxHeight: 600.w,
imageQuality: 80);//图片质量
苹果手机配置 info
<key>NSCameraUsageDescription</key>
<string>it is used to write one question and answer one question</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>it is used to write one question and answer one question</string>
<key>NSMicrophoneUsageDescription</key>
<string>it is used to record a video for publish in the third part</string>
银行卡识别
https://pub.dev/packages/flutter_tencent_ocr
排坑指南
腾讯云识别对图像大小有限制
Future bankOCR() async {
if (await Permission.camera.request().isGranted) {
final pickedFile = await picker.getImage(
source: ImageSource.camera,
maxWidth: 600.w,
maxHeight: 600.w,
imageQuality: 80);
if (pickedFile != null) {
_image = File(pickedFile.path);
BotToast.showLoading();
FlutterTencentOcr.bankCardOCR(
SecretId,
SecretKey,
GeneralOCRRequest.fromParams(
imageBase64: base64Encode(_image.readAsBytesSync())),
).then((onValue) {
if (onValue.bankInfo != null) {
setState(() {
bank = onValue.bankInfo;
cardNumber = onValue.cardNo;
});
} else {
BotToast.closeAllLoading();
BotToast.showText(
text: onValue.error.message, align: Alignment.center);
}
}).catchError(
(error) {
BotToast.closeAllLoading();
BotToast.showText(text: error, align: Alignment.center);
},
);
}
} else {
BotToast.showText(text: '未开启拍照权限', align: Alignment.center);
}
}
封装dio请求
全局拦截器(日志拦截器,错误拦截)
Flutter 安卓后台运行
插件:
网友评论