【发布时间】:2021-11-15 23:38:24
【问题描述】:
使用 flutter_barcode_scanner 时出现此错误:
未找到 com.google.android.gms.vision.barcode 的本地模块描述符类。 加载可选模块 com.google.android.gms.vision.barcode 时出错:com.google.android.gms.dynamite.DynamiteModule$LoadingException:找不到可接受的模块。本地版本为 0,远程版本为 0。 未找到 com.google.android.gms.vision.dynamite.barcode 的本地模块描述符类。 D/ViewRootImpl@9677bb1BarcodeCaptureActivity: ViewPostIme 指针 0
谁能帮帮我!
如何重现: 1-我只是运行包提供的示例 2-选择扫描条码 3-应用程序请求许可->接受授予许可 4-扫描仪一直扫描,没有捕捉到条码 5-错误出现在运行选项卡中的android studio中
main.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _scanBarcode = 'Unknown';
@override
void initState() {
super.initState();
}
Future<void> startBarcodeScanStream() async {
FlutterBarcodeScanner.getBarcodeStreamReceiver(
'#ff6666', 'Cancel', true, ScanMode.BARCODE)!
.listen((barcode) => print(barcode));
}
Future<void> scanQR() async {
String barcodeScanRes;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
barcodeScanRes = await FlutterBarcodeScanner.scanBarcode(
'#ff6666', 'Cancel', true, ScanMode.QR);
print(barcodeScanRes);
} on PlatformException {
barcodeScanRes = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_scanBarcode = barcodeScanRes;
});
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> scanBarcodeNormal() async {
String barcodeScanRes;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
barcodeScanRes = await FlutterBarcodeScanner.scanBarcode(
'#ff6666', 'Cancel', true, ScanMode.BARCODE);
print(barcodeScanRes);
} on PlatformException {
barcodeScanRes = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_scanBarcode = barcodeScanRes;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Barcode scan')),
body: Builder(builder: (BuildContext context) {
return Container(
alignment: Alignment.center,
child: Flex(
direction: Axis.vertical,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: () => scanBarcodeNormal(),
child: Text('Start barcode scan')),
ElevatedButton(
onPressed: () => scanQR(),
child: Text('Start QR scan')),
ElevatedButton(
onPressed: () => startBarcodeScanStream(),
child: Text('Start barcode scan stream')),
Text('Scan result : $_scanBarcode\n',
style: TextStyle(fontSize: 20))
]));
})));
}
}
【问题讨论】:
-
你能发布代码吗(即使它是随包提供的)。这将使 SO 用户更容易提供帮助。
-
好的,我会提供的
标签: flutter dart barcode barcode-scanner vision