13

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.

Crazy Lazy Cat
  • 13,595
  • 4
  • 30
  • 54
Gian Almada
  • 189
  • 1
  • 1
  • 10
  • Are you using this on Android, iOS or Web? Have you tried `flutter clean`? – Michel Feinstein Feb 06 '20 at 03:50
  • have you implemented `check` method in `Android` code? – Xihuny Feb 06 '20 at 04:41
  • @mFeinstein im using it both in android anf iOS, i tried flutter clean, and also remove package and add it again, but still same, – Gian Almada Feb 06 '20 at 06:56
  • 1
    Also a hot restart I guess? – Michel Feinstein Feb 06 '20 at 06:57
  • @Xihuny i dont know, i think i dont do that, i dont know how to implement that code in android – Gian Almada Feb 06 '20 at 06:58
  • yes, even i unistall the apk and run it again, but still the same – Gian Almada Feb 06 '20 at 07:06
  • What are you trying to do actually & where did you get this code? Please check example from official site here: https://pub.dev/packages/connectivity#-example-tab- – Xihuny Feb 06 '20 at 10:23
  • You are receiving the error because you have not implemented `check` method in android code. Here is how you can do it if you want to make your own method. https://flutter.dev/docs/development/platform-integration/platform-channels?tab=android-channel-java-tab – Xihuny Feb 06 '20 at 10:25
  • @Xihuny thank for your response, now my problem is solved by adding some line from example from official site on my android MainActivity.java, thank you. – Gian Almada Feb 07 '20 at 03:38
  • 1
    Yap All you have to to do is Stop your app and complete restart as @Crazy Lazy Cat mentioned below – Kunchok Tashi May 30 '20 at 11:08

5 Answers5

42

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

Crazy Lazy Cat
  • 13,595
  • 4
  • 30
  • 54
6

Flutter clean on terminal, stop the build and running again worked for me

viniciusbaca
  • 171
  • 2
  • 2
0

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.

Dennis
  • 1
  • actually, i want to detect network change, because i dont know how to show error when network is not connected or not available and do request get api when network is available and connected, in case internet connection is lost suddenly – Gian Almada Feb 06 '20 at 07:03
0

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"));
Gian Almada
  • 189
  • 1
  • 1
  • 10
  • after running app again it will generate whole file again, sry but its not help full – hio Jul 13 '21 at 17:18
0

Run

$ flutter clean

Stop debugging, start debugging. Should work.

Hamed
  • 5,867
  • 4
  • 32
  • 56