subscribeConnectivityChange static method

StreamSubscription<List<ConnectivityResult>> subscribeConnectivityChange(
  1. ConnectivityChangeListener? listener, {
  2. bool lookUp = false,
  3. String lookUpUrl = "google.com",
})

Implementation

static StreamSubscription<List<ConnectivityResult>> subscribeConnectivityChange(ConnectivityChangeListener? listener, {bool lookUp = false, String lookUpUrl = "google.com"}){
  final subscription = Connectivity().onConnectivityChanged.listen((List<ConnectivityResult> result) async {
    if(listener != null){
      final bool hasInternet = await hasConnection(lookUp: lookUp, lookUpUrl: lookUpUrl);
      listener(result.first, hasInternet);
    }
  });
  return subscription;
}