Home > Mobile >  How to change the interval where checking for internet connection happens from 10 seconds to 5 secon
How to change the interval where checking for internet connection happens from 10 seconds to 5 secon

Time:10-12

I was using internet connection checker flutter package and couldn't figure out how to change the interval where the checking for internet connection happens from the default 10 seconds?

InternetConnectionChecker().onStatusChange.listen((status) {
    add(OnInternetConnectionChanged(
        status == InternetConnectionStatus.disconnected ? false : true));
  });

I want to know where I can change the default interval for checking internet connection from 10 seconds to 5 seconds

CodePudding user response:

I'm writing this for version 0.0.1 3 of the https://pub.dev/packages/internet_connection_checker/ I'd try to override this the similar way as the addresses, but in this case it's the checkInterval variable:

final internetConnectionChecker = InternetConnectionChecker();
internetConnectionChecker.checkInterval = Duration(seconds: 5);
internetConnectionChecker.onStatusChange.listen((status) {
    add(OnInternetConnectionChanged(
        status == InternetConnectionStatus.disconnected ? false : true));
  });

I would not modify the package source code.

CodePudding user response:

According to the documentation, DEFAULT_INTERVAL is 10 seconds. Interval is the time between automatic checks.

checkInterval (which controls how often a check is made) defaults to this value. You can change it if you need to perform checks more often or otherwise.

Duration checkInterval = Duration(seconds: 5);

I didn't look too deep into this, but I managed to change it in the source code, and I think thats how its supposed to be done.

How to change it:

1- Right click on InternetConnectionStatus and go to definition.

2- Then cntr f Duration checkInterval

3- Change Duration = checkInterval = DEFAULT_INTERVAL to Duration = checkInterval = Duration(seconds: 5);

  • Related