feat(fl_query_connectivity_plus_adapter): only poll to check online when connection is false
This commit is contained in:
@@ -22,17 +22,22 @@ class InternetConnectivityChecker
|
|||||||
|
|
||||||
InternetConnectivityChecker(Duration duration)
|
InternetConnectivityChecker(Duration duration)
|
||||||
: controller = StreamController<bool>.broadcast() {
|
: controller = StreamController<bool>.broadcast() {
|
||||||
Timer.periodic(duration, (timer) async {
|
Timer? timer;
|
||||||
if (isAppPaused) {
|
Connectivity().onConnectivityChanged.listen((event) async {
|
||||||
return;
|
if (isAppPaused) return;
|
||||||
}
|
|
||||||
await hasConnection();
|
await hasConnection();
|
||||||
});
|
});
|
||||||
Connectivity().onConnectivityChanged.listen((event) async {
|
|
||||||
if (isAppPaused) {
|
onConnectionChanged.listen((connection) {
|
||||||
return;
|
if (!connection && timer == null) {
|
||||||
|
timer = Timer.periodic(duration, (timer) async {
|
||||||
|
if (isAppPaused) return;
|
||||||
|
await hasConnection();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
timer?.cancel();
|
||||||
|
timer = null;
|
||||||
}
|
}
|
||||||
await hasConnection();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ import 'package:fl_query_connectivity_plus_adapter/connection_checker.dart';
|
|||||||
class FlQueryConnectivityPlusAdapter extends ConnectivityAdapter {
|
class FlQueryConnectivityPlusAdapter extends ConnectivityAdapter {
|
||||||
final InternetConnectivityChecker _adapter;
|
final InternetConnectivityChecker _adapter;
|
||||||
FlQueryConnectivityPlusAdapter({
|
FlQueryConnectivityPlusAdapter({
|
||||||
Duration pollingDuration = const Duration(minutes: 5),
|
Duration pollingDuration = const Duration(seconds: 30),
|
||||||
}) : _adapter = InternetConnectivityChecker(pollingDuration);
|
}) : _adapter = InternetConnectivityChecker(pollingDuration);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
Reference in New Issue
Block a user