data_connection_checker icon indicating copy to clipboard operation
data_connection_checker copied to clipboard

No internet connection even though I have internet connection.

Open mixemer opened this issue 5 years ago • 29 comments

flutter: No internet :( Reason: flutter: [AddressCheckResult(AddressCheckOptions(InternetAddress('1.1.1.1', IPv4), 53, 0:00:10.000000), false), AddressCheckResult(AddressCheckOptions(InternetAddress('8.8.4.4', IPv4), 53, 0:00:10.000000), false), AddressCheckResult(AddressCheckOptions(InternetAddress('208.67.222.222', IPv4), 53, 0:00:10.000000), false)]

I am using a school wifi connection and data_connection_checker is failing when tries to connect internet. I tried a different wifi (my phone's), it worked.

I am hoping this can be fixed because the app I am developing is focusing on students and they will be at school most of the time :)

mixemer avatar Jan 16 '20 18:01 mixemer

Did you have an internet connection at the moment? Maybe you were on the network but the internet connection was not working. Have you also try to ping manually the different IPs from the documentation?

FlorianBouron avatar Jan 17 '20 20:01 FlorianBouron

I just updated to the last version of Flutter and this library has stopped working for me too. I have an internet connection, can ping the IPs from the documentation fine, but DataConnectionChecker().hasConnection sits there for several seconds and then returns false.

voivoed avatar Jan 26 '20 02:01 voivoed

My app isn't been accepted in Apple's store because it always says that there's no internet connection...

alvesluc avatar Jan 31 '20 15:01 alvesluc

I can confirm that DataConnectionChecker().hasConnection return false when running in release mode, but run normally in debug mode. Weird behavior.

dungnv2602 avatar Feb 09 '20 21:02 dungnv2602

So, there's no way to solve this?

On Sun, Feb 9, 2020, 18:18 Nguyễn Việt Dũng [email protected] wrote:

I can confirm that DataConnectionChecker().hasConnection return false when running in release mode, but run normally in debug mode. Weird behavior.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/komapeb/data_connection_checker/issues/6?email_source=notifications&email_token=AKGWGBM5ASAUKSJLGPQX7C3RCBXLHA5CNFSM4KHYU7UKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELGYM2I#issuecomment-583894633, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKGWGBP3PI2BGDVCDBHIO7TRCBXLHANCNFSM4KHYU7UA .

alvesluc avatar Feb 09 '20 21:02 alvesluc

Have you also try to ping manually the different IPs from the documentation?

Yes I had internet connection. It was working. I did not try to change IPs. However I used connectivity library and this library together. It works for now.

mixemer avatar Feb 13 '20 21:02 mixemer

My app isn't been accepted in Apple's store because it always says that there's no internet connection...

I have the same problem

spiderion avatar Feb 14 '20 16:02 spiderion

I can confirm that DataConnectionChecker().hasConnection return false when running in release mode, but run normally in debug mode. Weird behavior.

I am having the same issue. It all works fine on debug mode, but seems to always return false on release mode. 🤔

mrverdant13 avatar Feb 20 '20 03:02 mrverdant13

Same problem here. App Store rejected my build.

I think I have used v1.13.6-beta or v1.14.6-beta.

jans-y avatar Feb 21 '20 11:02 jans-y

I just solved it by adding the internet permission (<uses-permission android:name="android.permission.INTERNET" />) to the AndroidManifest (all of them). Hope it helps, guys.

mrverdant13 avatar Feb 22 '20 07:02 mrverdant13

because Apple is testing apps in IPv6 network!

fpv999 avatar Feb 23 '20 10:02 fpv999

I just solved it by adding the internet permission (<uses-permission android:name="android.permission.INTERNET" />) to the AndroidManifest (all of them). Hope it helps, guys.

Adding Android permission to iOS app won't solve things ;-)

fpv999 avatar Feb 23 '20 10:02 fpv999

because Apple is testing apps in IPv6 network!

Do you know a way to test apps in an ipv6 environment /network?

Mosamisa avatar Feb 24 '20 06:02 Mosamisa

https://medium.com/@mhalitk/test-ipv6-compatibility-of-ios-application-360d6a33bd23

fpv999 avatar Feb 24 '20 06:02 fpv999

This happens for me as well. I got rejected two times because of this and didn't know why because in my tests everything worked fine.

(anyway, this plugin is really great and thanks for contributors)

GyuriMajercsik avatar Feb 25 '20 12:02 GyuriMajercsik

What is wrong with the small part of code... why do you need plugin at all?

static final Duration _CONNECTIVITY_TIMEOUT = Duration(seconds: 1);

static Future _checkConnectivity() async { try { final result = await InternetAddress.lookup('google.com').timeout(_CONNECTIVITY_TIMEOUT); if (result != null && result.isNotEmpty && result.first?.rawAddress?.isNotEmpty == true) { return true; } } catch (e) { print(e); } return false; }

boskokg avatar Apr 25 '20 16:04 boskokg

but DNS addresses can be cached in local DNS servers.

fpv999 avatar Apr 25 '20 16:04 fpv999

when the apk is generated and wifi is used it works well but when it is passed to the connection by mobile data it does not work. It does not seem to detect the change to mobile data. In debug mode it works well choose to use the following code final List<InternetAddress> res = await InternetAddress.lookup('google.com').timeout( Duration(seconds: 5), ); I saw it here: https://stackoverflow.com/questions/49648022/check-whether-there-is-an-internet-connection-available-on-flutter-app

diegopq avatar Apr 27 '20 04:04 diegopq

I'm also facing this issue. When i changed default timeout for WIFI to less than or equal to 1 seconds it will not take too time and working fine but when i test with same configuration on mobile it return internet connection not available.

prasantco avatar May 21 '20 15:05 prasantco

I can confirm that DataConnectionChecker().hasConnection return false when running in release mode, but run normally in debug mode. Weird behavior.

Did you double check the AndroidManifest.xml contains following declaration? <uses-permission android:name="android.permission.INTERNET"/>

Android Studio will add such use-permission in debug mode automatically. However you should add it manually in release mode.

dokinkon avatar Jun 22 '20 08:06 dokinkon

I have implemented a solution taking inspiration from this plugin, I posted it on StackOverflow (so that people can try it and hopefully provide feedbacks). It seems to work fine but I would be really interested in feedbacks, I want to push it to prod at some point and testing network exceptions like these is really hard to do on your own.

https://stackoverflow.com/questions/49648022/check-whether-there-is-an-internet-connection-available-on-flutter-app/62537696#62537696

quentinleguennec avatar Jun 23 '20 15:06 quentinleguennec

I've added the IPv6 DNS addresses for Google, CloudFlare and OpenDNS and it seems to have solved the problem on IPv6-only networks. Similar to @quentinleguennec 's answer above, but still using data_connection_checker.

    List<AddressCheckOptions> addresses = List.from(DataConnectionChecker.DEFAULT_ADDRESSES);
    addresses.addAll([
      AddressCheckOptions(
        InternetAddress('2001:4860:4860::8888', type: InternetAddressType.IPv6), // Google
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
      AddressCheckOptions(
        InternetAddress('2001:4860:4860::8844', type: InternetAddressType.IPv6), // Google
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
      AddressCheckOptions(
        InternetAddress('2606:4700:4700::64', type: InternetAddressType.IPv6), // CloudFlare
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
      AddressCheckOptions(
        InternetAddress('2606:4700:4700::6400', type: InternetAddressType.IPv6), // CloudFlare
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
      AddressCheckOptions(
        InternetAddress('2620:119:35::35', type: InternetAddressType.IPv6), // OpenDNS
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
      AddressCheckOptions(
        InternetAddress('2620:119:53::53', type: InternetAddressType.IPv6), // OpenDNS
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
    ]);
    DataConnectionChecker().addresses = addresses;
    DataConnectionChecker().onStatusChange.listen((status) {
      // your usual code here
    });

red42 avatar Aug 14 '20 15:08 red42

I've added the IPv6 DNS addresses for Google, CloudFlare and OpenDNS and it seems to have solved the problem on IPv6-only networks. Similar to @quentinleguennec 's answer above, but still using data_connection_checker.

    List<AddressCheckOptions> addresses = List.from(DataConnectionChecker.DEFAULT_ADDRESSES);
    addresses.addAll([
      AddressCheckOptions(
        InternetAddress('2001:4860:4860::8888', type: InternetAddressType.IPv6), // Google
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
      AddressCheckOptions(
        InternetAddress('2001:4860:4860::8844', type: InternetAddressType.IPv6), // Google
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
      AddressCheckOptions(
        InternetAddress('2606:4700:4700::64', type: InternetAddressType.IPv6), // CloudFlare
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
      AddressCheckOptions(
        InternetAddress('2606:4700:4700::6400', type: InternetAddressType.IPv6), // CloudFlare
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
      AddressCheckOptions(
        InternetAddress('2620:119:35::35', type: InternetAddressType.IPv6), // OpenDNS
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
      AddressCheckOptions(
        InternetAddress('2620:119:53::53', type: InternetAddressType.IPv6), // OpenDNS
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
    ]);
    DataConnectionChecker().addresses = addresses;
    DataConnectionChecker().onStatusChange.listen((status) {
      // your usual code here
    });

I'm having false results when using your ipv6 addresses, do you know what is wrong? please advice

This is the result:

[AddressCheckResult(AddressCheckOptions(InternetAddress('1.1.1.1', IPv4), 53, 0:00:10.000000), true), AddressCheckResult(AddressCheckOptions(InternetAddress('8.8.4.4', IPv4), 53, 0:00:10.000000), true), AddressCheckResult(AddressCheckOptions(InternetAddress('208.67.222.222', IPv4), 53, 0:00:10.000000), true), AddressCheckResult(AddressCheckOptions(InternetAddress('2001:4860:4860::8888', IPv6), 53, 0:00:10.000000), false), AddressCheckResult(AddressCheckOptions(InternetAddress('2001:4860:4860::8844', IPv6), 53, 0:00:10.000000), false), AddressCheckResult(AddressCheckOptions(InternetAddress('2606:4700:4700::64', IPv6), 53, 0:00:10.000000), false), AddressCheckResult(AddressCheckOptions(InternetAddress('2606:4700:4700::6400', IPv6), 53, 0:00:10.000000), false), AddressCheckResult(AddressCheckOptions(InternetAddress('2620:119:35::35', IPv6), 53, 0:00:10.000000), false), AddressCheckResult(AddressCheckOptions(InternetAddress('2620:119:53::53', IPv6), 53, 0:00:10.000000), false)]

Edit: I'm using Android, seems like using Wi-Fi cannot ping ipv6, when using data ipv6 returns true. But since IOS can only use ipv6 for production, if IOS device connected to Wi-Fi, can it ping and return true?

Case: Android:

  • Wifi, ipv4 = true, ipv6 = false
  • Data, ipv4 = true, ipv6 = true IOS:
  • Wifi, ipv4 = ??, ipv6 = ??
  • Data, ipv4 = ??, ipv6 = ??

ahshingx95 avatar Aug 19 '20 05:08 ahshingx95

It shouldn't matter whether you are on wifi or mobile data. Can you confirm your Android on wifi has an ipv6 ip address? Your result suggests that wifi is ipv4 only.

red42 avatar Aug 19 '20 12:08 red42

replace this code with the old one:

static final List<AddressCheckOptions> DEFAULT_ADDRESSES = List.unmodifiable([ AddressCheckOptions( InternetAddress('1.0.0.1'), port: DEFAULT_PORT, timeout: DEFAULT_TIMEOUT, ), AddressCheckOptions( InternetAddress('8.8.4.4'), port: DEFAULT_PORT, timeout: DEFAULT_TIMEOUT, ), AddressCheckOptions( InternetAddress('208.69.38.205'), port: 80, timeout: DEFAULT_TIMEOUT, ), ]);

miguelflores1993 avatar Aug 22 '20 20:08 miguelflores1993

I had the same issue and this code solved, I am not using this package anymore,

static Future isInternetAvailable() async {

bool result;

try {
  final list = await InternetAddress.lookup('google.com');
  if (list.isNotEmpty && list[0].rawAddress.isNotEmpty) {
    result = true;
    print('CONNECTED!');
  }
} on SocketException catch (_) {
  print('NOT CONNECTED!');
  result = false;
  return result;
}

return result;

}

Source: https://stackoverflow.com/questions/49648022/check-whether-there-is-an-internet-connection-available-on-flutter-app

d-apps avatar Sep 07 '20 02:09 d-apps

i somebody i slooking for similar implemetation without this module here is the code:

import 'dart:io';

class InternetConnetionCheckerService {
  get hasConnection async {
    bool result;

    try {
      final list = await InternetAddress.lookup('google.com');
      if (list.isNotEmpty && list[0].rawAddress.isNotEmpty) {
        result = true;
      }
    } on SocketException catch (_) {
      result = false;
      return result;
    }

    return result;
  }

  Stream<bool> get onStatusChange =>
      Stream.periodic(Duration(seconds: 10)).asyncMap<bool>((c) async {
        return await hasConnection;
      }).distinct();
}

vytautas-pranskunas- avatar Jan 11 '21 14:01 vytautas-pranskunas-

that's bad. Local DNS resolving can work on cached addresses sometimes.

fpv999 avatar Jan 11 '21 14:01 fpv999

I've added the IPv6 DNS addresses for Google, CloudFlare and OpenDNS and it seems to have solved the problem on IPv6-only networks. Similar to @quentinleguennec 's answer above, but still using data_connection_checker.

    List<AddressCheckOptions> addresses = List.from(DataConnectionChecker.DEFAULT_ADDRESSES);
    addresses.addAll([
      AddressCheckOptions(
        InternetAddress('2001:4860:4860::8888', type: InternetAddressType.IPv6), // Google
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
      AddressCheckOptions(
        InternetAddress('2001:4860:4860::8844', type: InternetAddressType.IPv6), // Google
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
      AddressCheckOptions(
        InternetAddress('2606:4700:4700::64', type: InternetAddressType.IPv6), // CloudFlare
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
      AddressCheckOptions(
        InternetAddress('2606:4700:4700::6400', type: InternetAddressType.IPv6), // CloudFlare
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
      AddressCheckOptions(
        InternetAddress('2620:119:35::35', type: InternetAddressType.IPv6), // OpenDNS
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
      AddressCheckOptions(
        InternetAddress('2620:119:53::53', type: InternetAddressType.IPv6), // OpenDNS
        port: DataConnectionChecker.DEFAULT_PORT,
        timeout: DataConnectionChecker.DEFAULT_TIMEOUT,
      ),
    ]);
    DataConnectionChecker().addresses = addresses;
    DataConnectionChecker().onStatusChange.listen((status) {
      // your usual code here
    });

I'm having false results when using your ipv6 addresses, do you know what is wrong? please advice

This is the result:

[AddressCheckResult(AddressCheckOptions(InternetAddress('1.1.1.1', IPv4), 53, 0:00:10.000000), true), AddressCheckResult(AddressCheckOptions(InternetAddress('8.8.4.4', IPv4), 53, 0:00:10.000000), true), AddressCheckResult(AddressCheckOptions(InternetAddress('208.67.222.222', IPv4), 53, 0:00:10.000000), true), AddressCheckResult(AddressCheckOptions(InternetAddress('2001:4860:4860::8888', IPv6), 53, 0:00:10.000000), false), AddressCheckResult(AddressCheckOptions(InternetAddress('2001:4860:4860::8844', IPv6), 53, 0:00:10.000000), false), AddressCheckResult(AddressCheckOptions(InternetAddress('2606:4700:4700::64', IPv6), 53, 0:00:10.000000), false), AddressCheckResult(AddressCheckOptions(InternetAddress('2606:4700:4700::6400', IPv6), 53, 0:00:10.000000), false), AddressCheckResult(AddressCheckOptions(InternetAddress('2620:119:35::35', IPv6), 53, 0:00:10.000000), false), AddressCheckResult(AddressCheckOptions(InternetAddress('2620:119:53::53', IPv6), 53, 0:00:10.000000), false)]

Edit: I'm using Android, seems like using Wi-Fi cannot ping ipv6, when using data ipv6 returns true. But since IOS can only use ipv6 for production, if IOS device connected to Wi-Fi, can it ping and return true?

Case: Android:

  • Wifi, ipv4 = true, ipv6 = false
  • Data, ipv4 = true, ipv6 = true IOS:
  • Wifi, ipv4 = ??, ipv6 = ??
  • Data, ipv4 = ??, ipv6 = ??

Are you using port 443?

Nightfury-5 avatar Mar 09 '21 17:03 Nightfury-5