subscribe method
Listen to InternetConnectionChecker.onStatusChange
and returns Stream
Implementation
Stream<bool> subscribe() {
late final InternetConnectionChecker icc;
if (hostname != null && port != null) {
icc = InternetConnectionChecker.createInstance(
checkInterval: checkInterval,
addresses: [AddressCheckOptions(hostname: hostname!, port: port!)]);
} else {
icc = InternetConnectionChecker.createInstance(
checkInterval: checkInterval);
}
final sc = StreamController<bool>();
_listener = icc.onStatusChange.listen((status) {
switch (status) {
case InternetConnectionStatus.connected:
sc.add(true);
break;
case InternetConnectionStatus.disconnected:
sc.add(false);
break;
}
});
return sc.stream;
}