作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试通过以下方式创建条形码扫描仪: https://pub.dev/packages/flutter_barcode_scanner/install .
当我运行我的代码时,我得到这个错误:
E/flutter ( 9248): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method scanBarcode on channel flutter_barcode_scanner)
E/flutter ( 9248): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:165:7)
E/flutter ( 9248): <asynchronous suspension>
E/flutter ( 9248): #1 FlutterBarcodeScanner.scanBarcode (package:flutter_barcode_scanner/flutter_barcode_scanner.dart:43:9)
E/flutter ( 9248): <asynchronous suspension>
E/flutter ( 9248): #2 _MyAppState.scanBarcodeNormal (package:styleupapp1/main.dart:46:24)
E/flutter ( 9248): <asynchronous suspension>
E/flutter ( 9248):
这是我的代码:
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;
try {
barcodeScanRes = await FlutterBarcodeScanner.scanBarcode(
'#ff6666', 'Cancel', true, ScanMode.QR);
print(barcodeScanRes);
} on PlatformException {
barcodeScanRes = 'Failed to get platform version.';
}
//barcode scanner flutter ant
setState(() {
_scanBarcode = barcodeScanRes;
});
}
Future<void> scanBarcodeNormal() async {
String barcodeScanRes;
try {
barcodeScanRes = await FlutterBarcodeScanner.scanBarcode(
'#ff6666', 'Cancel', true, ScanMode.BARCODE);
print(barcodeScanRes);
} on PlatformException {
barcodeScanRes = 'Failed to get platform version.';
}
if (!mounted) return;
setState(() {
_scanBarcode = barcodeScanRes;
});
}
//barcode scanner flutter ant
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: const Text('Barcode Scanner')),
body: Builder(builder: (BuildContext context) {
return Container(
alignment: Alignment.center,
child: Flex(
direction: Axis.vertical,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: () => scanBarcodeNormal(),
child: const Text('Barcode scan')),
ElevatedButton(
onPressed: () => scanQR(),
child: const Text('QR scan')),
ElevatedButton(
onPressed: () => startBarcodeScanStream(),
child: const Text('Barcode scan stream')),
Text('Scan result : $_scanBarcode\n',
style: const TextStyle(fontSize: 20))
]));
})));
}
}
有没有人遇到过这个错误?我不知道该怎么办我尝试了不同的方法和包,但每个人都给了我同样的错误。感谢您的回答,这对我来说非常重要。
我问过一次,但没有人回答。我真的需要修复它。
最佳答案
修改所有引用FlutterFragmentActivity
为FlutterActivity
Java:
public class MainActivity extends FlutterActivity
或者对于 Kotlin:
class MainActivity: FlutterActivity()
更多信息在这里:Plugin Api Migration
关于android - 未处理的异常 : MissingPluginException(No implementation found for method scanBarcode on channel flutter_barcode_scanner),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70562128/
我正在尝试通过以下方式创建条形码扫描仪: https://pub.dev/packages/flutter_barcode_scanner/install . 当我运行我的代码时,我得到这个错误: E
尝试运行我的 flutter 项目时,我得到: Error running pod install 我试过了: flutter 净 flutter 升级 flutter 医生的一切都很好 iOS/Po
我是一名优秀的程序员,十分优秀!