![](/img/trans.png)
[英](No implementation found for method init on channel plugins.flutter.io/google_sign_in
[英]Flutter based Android app throwing MissingPluginException(No implementation found for method on channel)
我正在嘗試使我的 android 應用程序的本機端與 Flutter 進行通信。
這是在 Flutter 端:
static const platform = const MethodChannel('getHallInfo');
@override
void initState() {
testing().then((String lst) {
setState(() {
if (lst != null) str = lst;
});
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[Text(str)],
);
}
static Future<String> testing() async {
String lst;
try {
lst = await platform.invokeMethod('getHalls');
} catch (e) {
print(e.toString());
}
return lst;
}
這是在本機 Java 上:
private static final String CHANNEL = "getHallInfo";
super.configureFlutterEngine(getFlutterEngine());
GeneratedPluginRegistrant.registerWith(getFlutterEngine());
new MethodChannel(getFlutterEngine().getDartExecutor().getBinaryMessenger(), CHANNEL).setMethodCallHandler(new MethodChannel.MethodCallHandler() {
@Override
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
if (methodCall.method.equals("getHalls")) {
String mm= "Succeeded";
System.out.println("Entered");
result.success(mm);
}
}
});
我的 Pubspec.yaml:
name: flutterModule
description: A new flutter module project.
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
flutter_svg: ^0.17.4
google_fonts: ^1.1.0
intl: ^0.16.1
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- assets/icons/
module:
androidX: true
androidPackage: com.example.flutterModule
iosBundleIdentifier: com.example.flutterModule
這是我得到的錯誤:
MissingPluginException(在通道 getHallInfo 上找不到方法 getHalls 的實現)
注意: “輸入”顯示在終端上
編輯:這些是我嘗試過的事情:
但是這個例外仍然存在。
您只需要停止應用程序並重新啟動它。
在停止應用程序之前,請確保您確實pub get
。 使用命令。
flutter pub get
你只需要運行
Flutter clean
然后再次重新啟動/運行您的應用程序
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.