Reputation: 551
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.
Upvotes: 3
Views: 912
Reputation: 1379
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');
}
Upvotes: 1