3

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.

Rock
  • 511
  • 2
  • 7
  • 18

1 Answers1

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
  • 1
    How 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