How can I continuously check internet connection for whole application(I mean all classes and widgets) and prompt the pop-up dialog when the connection is lost. Please provide an example if it is possible.
Asked
Active
Viewed 890 times
3
-
have you implement this feature ? because I also wanted to do this in my app. – Mrunal Mar 14 '21 at 06:47
1 Answers
1
You need to use the Connectivity Plugin.
import 'dart:io';
try {
final result = await InternetAddress.lookup('google.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
print('connected');
}
} on SocketException catch (_) {
print('not connected');
}

Bilaal Abdel Hassan
- 1,181
- 2
- 12
- 20
-
1How can i implement it in Main() and also Main does not have context so I cant prompt pop-up there ? – Rock Sep 21 '20 at 14:39