0

I got many solutions but there is no way to apply check internet is connected or not in complete flutter app. Please help to get out of it and let me know the solutions for checking its in one time.

Nisha Jain
  • 637
  • 6
  • 14
  • Does this answer your question? [Check whether there is an Internet connection available on Flutter app](https://stackoverflow.com/questions/49648022/check-whether-there-is-an-internet-connection-available-on-flutter-app) – maxmitz Jun 24 '22 at 15:04
  • No.... i want internet check throughout the whole app in one time code. – Nisha Jain Jun 24 '22 at 15:09
  • You can set up a Stream listener. See the second answer here: https://stackoverflow.com/a/56959146/12349734 – MendelG Jun 24 '22 at 15:11
  • Is there any way to check internet connectivity in all screens of app? I tried many solutions but have to check internet in each file. I want to check all files at once. – Nisha Jain Jun 24 '22 at 15:13

1 Answers1

0

Use internet connection checker internet_connection_checker

InternetConnectionChecker().checkInterval = Duration(seconds: 10);
      InternetConnectionChecker().onStatusChange.listen(
        (InternetConnectionStatus status) {
          switch (status) {
            case InternetConnectionStatus.connected:
              // ignore: avoid_print
              print('Data connection is available.');
              internetAvailable = true;
              setState(() {});
              break;
            case InternetConnectionStatus.disconnected:
              // ignore: avoid_print
              print('You are disconnected from the internet.');
              internetAvailable = false;
              setState(() {});
              break;
          }
        },
      );

Then based on the internetAvailable add the first screen

return internetAvailable? Center(child:Text("no internet")):HomePage()
Kaushik Chandru
  • 15,510
  • 2
  • 12
  • 30