gpt4 book ai didi

android - 未处理的异常 : MissingPluginException(No implementation found for method scanBarcode on channel flutter_barcode_scanner)

转载 作者:行者123 更新时间:2023-12-04 23:58:46 54 4
gpt4 key购买 nike

我正在尝试通过以下方式创建条形码扫描仪: 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))
]));
})));
}
}

有没有人遇到过这个错误?我不知道该怎么办我尝试了不同的方法和包,但每个人都给了我同样的错误。感谢您的回答,这对我来说非常重要。

我问过一次,但没有人回答。我真的需要修复它。

最佳答案

修改所有引用FlutterFragmentActivityFlutterActivity

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/

54 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com