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.
Asked
Active
Viewed 103 times
0
-
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 Answers
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
-
Thank you for the solution. By using this i have to add this in all widgets. " return internetAvailable? Center(child:Text("no internet")):HomePage() " right? – Nisha Jain Jun 24 '22 at 15:58
-
No you can use this in your main.dart and return the first screen – Kaushik Chandru Jun 24 '22 at 16:01
-
I have 4 apps and there are around 200+ screens. Is there any best way to add internet check in all screens in one time add. – Nisha Jain Jun 24 '22 at 16:01
-
-
-
-
-
-
I tried adding in both files. For now i added this internet check in every screen. Will see later. BTW Thanks alot. – Nisha Jain Jun 27 '22 at 10:59
-
Please accept the answers if it helped so it will be useful for others – Kaushik Chandru Jun 27 '22 at 12:18
-
-
In main. dart you are returning a material app. Inside the material app you will be returning the first screen. In this place add the internet checker. If internet is available return the page or else a placeholder for no internet. It's working for me in all screens. – Kaushik Chandru Jun 27 '22 at 17:06
-