feat(fl_query_connectivity_plus_adapter): only poll to check online when connection is false

This commit is contained in:
Kingkor Roy Tirtho
2023-10-14 15:10:52 +06:00
parent 363404f9ed
commit a06b7508ac
2 changed files with 14 additions and 9 deletions
@@ -22,17 +22,22 @@ class InternetConnectivityChecker
InternetConnectivityChecker(Duration duration)
: controller = StreamController<bool>.broadcast() {
Timer.periodic(duration, (timer) async {
if (isAppPaused) {
return;
}
Timer? timer;
Connectivity().onConnectivityChanged.listen((event) async {
if (isAppPaused) return;
await hasConnection();
});
Connectivity().onConnectivityChanged.listen((event) async {
if (isAppPaused) {
return;
onConnectionChanged.listen((connection) {
if (!connection && timer == null) {
timer = Timer.periodic(duration, (timer) async {
if (isAppPaused) return;
await hasConnection();
});
} else {
timer?.cancel();
timer = null;
}
await hasConnection();
});
}