问题
I already added connectivity plugin on my pubspec.yaml
.
connectivity: ^0.4.6
But still getting this error:
E/flutter ( 4789): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method check on channel plugins.flutter.io/connectivity)
E/flutter ( 4789): #0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:314:7)
E/flutter ( 4789):
E/flutter ( 4789): #1 Connectivity.checkConnectivity (package:connectivity/connectivity.dart:73:47)
error connectivity is from this line :
Future<ConnectivityResult> checkConnectivity() async {
final String result = await methodChannel.invokeMethod<String>('check');
return _parseConnectivityResult(result);
}
and I never modified this package, But still get this error no matter what version of this plugin that I use. I hope anyone can help me to solve this error, thank you. Sorry for my bad English.
回答1:
This error mostly occurs when you try to Hot Reload or Hot Restart after just adding new package to your pubspec.yaml
.
Just stop the running project(app) and then freshly run it again. So that the added package(which contains the implementations) also pushed to the device
回答2:
Following is irrelevant to above questing but the end result is same. I had complications with connectivity plugin and IOS configuration. So I use following method to check whether my app is connected to internet:
static Future<bool> checkInternetConnectivity() async {
bool isConnected;
try {
final result = await InternetAddress.lookup('google.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
isConnected = true;
}
} on SocketException catch (_) {
isConnected = false;
}
return isConnected;
}
AppUtil.checkInternetConnectivity().then((isOnline) async {
if (isOnline) {...} else {...}
})
I never saw google website going down. If I wanted to listen to internet connectivity, I use timer.
If you want to check mobile data connectivity or wifi data connectivity, sorry! you will still have to go on implementing connectivity.
回答3:
this problem is solved by manuaally edit and add line on your android GeneratedPluginRegistrant, like this:
import io.flutter.plugins.connectivity.ConnectivityPlugin;
ConnectivityPlugin.registerWith(registry.registrarFor("io.flutter.plugins.connectivity.ConnectivityPlugin"));
回答4:
Flutter clean on terminal, stop the build and running again worked for me
来源:https://stackoverflow.com/questions/60087278/unhandled-exception-missingpluginexceptionno-implementation-found-for-method-c