InternetConnectivityChecker constructor

InternetConnectivityChecker(
  1. Duration duration
)

Implementation

InternetConnectivityChecker(Duration duration)
    : controller = StreamController<bool>.broadcast() {
  Timer? timer;
  Connectivity().onConnectivityChanged.listen((event) async {
    if (isAppPaused) return;
    await hasConnection();
  });

  onConnectionChanged.listen((connection) {
    if (!connection && timer == null) {
      timer = Timer.periodic(duration, (timer) async {
        if (isAppPaused) return;
        await hasConnection();
      });
    } else {
      timer?.cancel();
      timer = null;
    }
  });
}