Flutter 使用照相包拍照,并检查条形码阅读器
**首先,我为这个大代码道歉。 我的Flitter应用程序使用pugin和条形码阅读器插件来拍摄和扫描nid。对于拍照帮助,当我拍照并尝试读取条形码时,它不起作用,但相同的代码按软件包工作,但我想使用相机软件包。任何帮助都将是非常有用的** 告诉我这个错误Flutter 使用照相包拍照,并检查条形码阅读器,flutter,dart,barcode,Flutter,Dart,Barcode,**首先,我为这个大代码道歉。 我的Flitter应用程序使用pugin和条形码阅读器插件来拍摄和扫描nid。对于拍照帮助,当我拍照并尝试读取条形码时,它不起作用,但相同的代码按软件包工作,但我想使用相机软件包。任何帮助都将是非常有用的** 告诉我这个错误 W/(19978): Unable to open '/system/framework/qcom.fmradio.jar': No such file or directory W/art (19978): Failed t
W/(19978): Unable to open '/system/framework/qcom.fmradio.jar': No such
file or directory
W/art (19978): Failed to open zip
archive'/system/framework/qcom.fmradio.jar': I/O Error
W/DynamiteModule(19978): Local module descriptor class for
com.google.firebase.ml.vision.dynamite.barcode not found.
W/DynamiteModule(19978): Local module descriptor class for
com.google.android.gms.vision.dynamite.barcode not found.
I/DynamiteModule(19978): Considering local module
com.google.android.gms.vision.dynamite.barcode:0 and remote module
com.google.android.gms.vision.dynamite.barcode:0
I/DynamiteModule(19978): Considering local module
com.google.android.gms.vision.barcode:0 and remote module
com.google.android.gms.vision.barcode:1
I/DynamiteModule(19978): Selected remote version of
com.google.android.gms.vision.barcode, version >= 1
V/DynamiteModule(19978): Dynamite loader version >= 2, using
loadModule2NoCrashUtils
W/ResourceType(19978): ResTable_typeSpec entry count inconsistent: given 67,
previously 69
D/ResourcesManager(19978): For user 0 new overlays fetched Null
W/System (19978): ClassLoader referenced unknown path:
/data/data/com.google.android.gms/app_chimera/m/00000009/n/armeabi
D/ResourcesManager(19978): For user 0 new overlays fetched Null
启动摄像头并拍照读取条形码
class _EKycCustomerNidBackSideState extends State<EKycCustomerNidBackSide> {
String imagePath;
CameraController _controller;
Future<void> _initializeControllerFuture;
var barcodeString;
BarcodeScanner barcodeScanner;
List<Barcode> barcodes;
@override
void initState() {
super.initState();
_controller = CameraController(
widget.camera,
ResolutionPreset.high,
);
_initializeControllerFuture = _controller.initialize();
}
@override
void dispose() {
_controller?.dispose();
super.dispose();
}
errorDialog(String title, String msg) {
showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text(
title,
style: TextStyle(fontWeight: FontWeight.bold),
),
content: Text(
msg,
textAlign: TextAlign.center,
),
actions: [
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DisplayPictureScreen(
nameString: widget.customerid,
),
),
);
},
child: Text('SKIP'),
),
TextButton(
onPressed: () => Navigator.pop(context),
child: Text('TRY AGAIN'),
),
],
),
);
}
Future decode() async {
await _initializeControllerFuture;
await _controller.lockCaptureOrientation();
var barcodeString = '';
var image = await _controller.takePicture();
final inputImage = InputImage.fromFilePath(image.path);
barcodeScanner = GoogleMlKit.vision.barcodeScanner();
final result = await barcodeScanner.processImage(inputImage);
setState(() {
imagePath = image.path;
barcodes = result;
});
barcodeString = barcodes[0].barcodeUnknown.rawValue;
if (barcodeString.replaceAll(' ', '').contains("6427886723")) {
print('nid match');
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DisplayPictureScreen(
barcode: barcodeString,
),
),
);
} else {
print('nid not match');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('NID BackSide Image Capture'),
actions: [
IconButton(
icon: Icon(Icons.more_vert),
onPressed: () {},
)
],
),
body: FutureBuilder<void>(
future: _initializeControllerFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: Stack(
fit: StackFit.expand,
children: <Widget>[
CameraPreview(_controller),
Positioned(
left: MediaQuery.of(context).size.width * 0.3,
top: MediaQuery.of(context).size.height * 0.1,
child: Text('NID Back Image Capture'),
),
Positioned(
top: MediaQuery.of(context).size.height * 0.20,
left: 10,
right: 10,
bottom: MediaQuery.of(context).size.height * 0.35,
child: Container(
height: MediaQuery.of(context).size.height * 0.35,
width: MediaQuery.of(context).size.width * 0.9,
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 1.5),
borderRadius: BorderRadius.circular(12.0),
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
width: double.infinity,
height: 140.0,
padding: EdgeInsets.all(20.0),
color: Colors.grey,
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius:
BorderRadius.all(Radius.circular(50.0)),
onTap: () async {
await decode();
},
child: Column(
children: [
Text(
'Put your Nid inside the frame and take a picture',
style: TextStyle(
fontWeight: FontWeight.bold),
),
Container(
padding: EdgeInsets.all(4.0),
child: Image.asset(
'assets/images/shutter_1.png',
width: 72.0,
height: 72.0,
),
),
],
),
),
),
),
],
),
),
),
],
),
),
);
} else {
return Center(
child: CircularProgressIndicator(),
);
}
},
),
);
}
}
class\EKycCustomerNidBackSideState扩展状态{
字符串图像路径;
摄像机控制器(CameraController)控制器;;
未来(初始化控制未来);
var条码串;
条码扫描器条码扫描器;
列出条形码;
@凌驾
void initState(){
super.initState();
_控制器=摄像机控制器(
照相机,
分辨率预置,高,
);
_initializeControllerFuture=_controller.initialize();
}
@凌驾
无效处置(){
_控制器?.dispose();
super.dispose();
}
errorDialog(字符串标题、字符串消息){
显示对话框(
上下文:上下文,
生成器:(\u)=>AlertDialog(
标题:正文(
标题
样式:TextStyle(fontWeight:fontWeight.bold),
),
内容:文本(
味精,
textAlign:textAlign.center,
),
行动:[
文本按钮(
已按下:(){
导航器。推(
上下文
材料路线(
生成器:(上下文)=>DisplayPictureScreen(
名称字符串:widget.customerid,
),
),
);
},
子项:文本('SKIP'),
),
文本按钮(
onPressed:()=>Navigator.pop(上下文),
子项:文本(“重试”),
),
],
),
);
}
Future decode()异步{
等待(u initializeControllerFuture);;
等待_controller.lockCaptureOrientation();
var barcodeString='';
var image=wait_controller.takePicture();
final inputImage=inputImage.fromFilePath(image.path);
barcodeScanner=GoogleMlKit.vision.barcodeScanner();
最终结果=等待条形码扫描仪.processImage(inputImage);
设置状态(){
imagePath=image.path;
条形码=结果;
});
barcodeString=条形码[0]。barcodeUnknown.rawValue;
如果(barcodeString.replaceAll(“”,“)。包含(“6427886723”)){
打印(“nid匹配”);
导航器。推(
上下文
材料路线(
生成器:(上下文)=>DisplayPictureScreen(
条形码:条形码字符串,
),
),
);
}否则{
打印(“nid不匹配”);
}
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“NID背面图像捕获”),
行动:[
图标按钮(
图标:图标(更多图标),
按下:(){},
)
],
),
正文:未来建设者(
未来:_initializeControllerFuture,
生成器:(上下文,快照){
if(snapshot.connectionState==connectionState.done){
返回容器(
高度:MediaQuery.of(context).size.height,
宽度:MediaQuery.of(context).size.width,
孩子:AspectRatio(
aspectRatio:_controller.value.aspectRatio,
子:堆栈(
fit:StackFit.expand,
儿童:[
CameraPreview(_控制器),
定位(
左:MediaQuery.of(context).size.width*0.3,
顶部:MediaQuery.of(context).size.height*0.1,
子项:文本('NID返回图像捕获'),
),
定位(
顶部:MediaQuery.of(上下文).size.height*0.20,
左:10,,
右:10,,
底部:MediaQuery.of(context).size.height*0.35,
子:容器(
高度:MediaQuery.of(上下文).size.height*0.35,
宽度:MediaQuery.of(context).size.width*0.9,
装饰:盒子装饰(
边框:边框。全部(颜色:Colors.red,宽度:1.5),
边界半径:边界半径。圆形(12.0),
),
),
),
对齐(
对齐:对齐.bottomCenter,
子:容器(
宽度:double.infinity,
身高:140.0,
填充:所有边缘设置(20.0),
颜色:颜色。灰色,
子:堆栈(
儿童:[
对齐(
对齐:对齐.center,
儿童:材料(
颜色:颜色。透明,
孩子:InkWell(
边界半径:
边界半径所有(半径圆形(50.0)),
onTap:()异步{
等待解码();
},
子:列(
儿童:[
正文(
“把你的Nid放进相框里,然后拍照”,
样式:TextStyle(
fontWeight:fontWeight.bold),
),
容器(
填充:所有边缘设置(4.0),
子:Image.asset(
“资产/图像/快门_1.png”,
宽度:72.0,
身高:72.0,