refetchOnReconnect support added for Query
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
import FlutterMacOS
|
import FlutterMacOS
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
import connectivity_plus_macos
|
||||||
|
|
||||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||||
|
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
# Generated by pub
|
# Generated by pub
|
||||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||||
packages:
|
packages:
|
||||||
|
args:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: args
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.3.1"
|
||||||
async:
|
async:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -43,6 +50,48 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.16.0"
|
version: "1.16.0"
|
||||||
|
connectivity_plus:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: connectivity_plus
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.3.5"
|
||||||
|
connectivity_plus_linux:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: connectivity_plus_linux
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.3.1"
|
||||||
|
connectivity_plus_macos:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: connectivity_plus_macos
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.2.4"
|
||||||
|
connectivity_plus_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: connectivity_plus_platform_interface
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.2.1"
|
||||||
|
connectivity_plus_web:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: connectivity_plus_web
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.2.2"
|
||||||
|
connectivity_plus_windows:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: connectivity_plus_windows
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.2.2"
|
||||||
crypto:
|
crypto:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -57,6 +106,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.4"
|
version: "1.0.4"
|
||||||
|
dbus:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: dbus
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.7.5"
|
||||||
fake_async:
|
fake_async:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -64,6 +120,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.0"
|
version: "1.3.0"
|
||||||
|
ffi:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: ffi
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.1"
|
||||||
fl_query:
|
fl_query:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -95,6 +158,11 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
flutter_web_plugins:
|
||||||
|
dependency: transitive
|
||||||
|
description: flutter
|
||||||
|
source: sdk
|
||||||
|
version: "0.0.0"
|
||||||
http:
|
http:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -109,6 +177,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.0.1"
|
version: "4.0.1"
|
||||||
|
js:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: js
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.6.4"
|
||||||
lints:
|
lints:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -137,6 +212,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.7.0"
|
version: "1.7.0"
|
||||||
|
nm:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: nm
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.5.0"
|
||||||
path:
|
path:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -144,6 +226,20 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.1"
|
version: "1.8.1"
|
||||||
|
petitparser:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: petitparser
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "5.0.0"
|
||||||
|
plugin_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: plugin_platform_interface
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.2"
|
||||||
sky_engine:
|
sky_engine:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
@@ -212,6 +308,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.2"
|
version: "2.1.2"
|
||||||
|
xml:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: xml
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "6.1.0"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.17.1 <3.0.0"
|
dart: ">=2.17.1 <3.0.0"
|
||||||
flutter: ">=3.0.0"
|
flutter: ">=3.0.0"
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
#include "generated_plugin_registrant.h"
|
#include "generated_plugin_registrant.h"
|
||||||
|
|
||||||
|
#include <connectivity_plus_windows/connectivity_plus_windows_plugin.h>
|
||||||
|
|
||||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||||
|
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
|
||||||
|
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
list(APPEND FLUTTER_PLUGIN_LIST
|
list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
|
connectivity_plus_windows
|
||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# This is a generated file; do not edit or check into version control.
|
||||||
|
connectivity_plus=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.5/
|
||||||
|
connectivity_plus_linux=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.3.1/
|
||||||
|
connectivity_plus_macos=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_macos-1.2.4/
|
||||||
|
connectivity_plus_web=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.2/
|
||||||
|
connectivity_plus_windows=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_windows-1.2.2/
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.5/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.5/","native_build":true,"dependencies":[]}],"macos":[{"name":"connectivity_plus_macos","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_macos-1.2.4/","native_build":true,"dependencies":[]}],"linux":[{"name":"connectivity_plus_linux","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_linux-1.3.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"connectivity_plus_windows","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_windows-1.2.2/","native_build":true,"dependencies":[]}],"web":[{"name":"connectivity_plus_web","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.2/","dependencies":[]}]},"dependencyGraph":[{"name":"connectivity_plus","dependencies":["connectivity_plus_linux","connectivity_plus_macos","connectivity_plus_web","connectivity_plus_windows"]},{"name":"connectivity_plus_linux","dependencies":[]},{"name":"connectivity_plus_macos","dependencies":[]},{"name":"connectivity_plus_web","dependencies":[]},{"name":"connectivity_plus_windows","dependencies":[]}],"date_created":"2022-06-22 21:14:04.467520","version":"3.0.1"}
|
||||||
@@ -31,6 +31,7 @@ class QueryJob<T extends Object, Outside> {
|
|||||||
|
|
||||||
// got from global options
|
// got from global options
|
||||||
bool? refetchOnMount;
|
bool? refetchOnMount;
|
||||||
|
bool? refetchOnReconnect;
|
||||||
Duration? staleTime;
|
Duration? staleTime;
|
||||||
Duration? cacheTime;
|
Duration? cacheTime;
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ class QueryJob<T extends Object, Outside> {
|
|||||||
this.enabled,
|
this.enabled,
|
||||||
this.refetchInterval,
|
this.refetchInterval,
|
||||||
this.refetchOnMount,
|
this.refetchOnMount,
|
||||||
|
this.refetchOnReconnect,
|
||||||
}) : _queryKey = queryKey;
|
}) : _queryKey = queryKey;
|
||||||
|
|
||||||
String get queryKey => _queryKey;
|
String get queryKey => _queryKey;
|
||||||
@@ -67,6 +69,7 @@ class QueryJob<T extends Object, Outside> {
|
|||||||
bool? enabled,
|
bool? enabled,
|
||||||
Duration? refetchInterval,
|
Duration? refetchInterval,
|
||||||
bool? refetchOnMount,
|
bool? refetchOnMount,
|
||||||
|
bool? refetchOnReconnect,
|
||||||
}) {
|
}) {
|
||||||
return (String queryKey) {
|
return (String queryKey) {
|
||||||
if (preQueryKey != null) queryKey = "$preQueryKey#$queryKey";
|
if (preQueryKey != null) queryKey = "$preQueryKey#$queryKey";
|
||||||
@@ -81,6 +84,7 @@ class QueryJob<T extends Object, Outside> {
|
|||||||
enabled: enabled,
|
enabled: enabled,
|
||||||
refetchInterval: refetchInterval,
|
refetchInterval: refetchInterval,
|
||||||
refetchOnMount: refetchOnMount,
|
refetchOnMount: refetchOnMount,
|
||||||
|
refetchOnReconnect: refetchOnReconnect,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||||
import 'package:fl_query/src/base_operation.dart';
|
import 'package:fl_query/src/base_operation.dart';
|
||||||
import 'package:fl_query/src/models/query_job.dart';
|
import 'package:fl_query/src/models/query_job.dart';
|
||||||
import 'package:fl_query/src/query_bowl.dart';
|
import 'package:fl_query/src/query_bowl.dart';
|
||||||
@@ -44,6 +45,7 @@ class Query<T extends Object, Outside> extends BaseOperation<T, QueryStatus> {
|
|||||||
QueryTaskFunction<T, Outside> task;
|
QueryTaskFunction<T, Outside> task;
|
||||||
|
|
||||||
bool? refetchOnMount;
|
bool? refetchOnMount;
|
||||||
|
bool? refetchOnReconnect;
|
||||||
|
|
||||||
final T? _initialData;
|
final T? _initialData;
|
||||||
|
|
||||||
@@ -83,6 +85,7 @@ class Query<T extends Object, Outside> extends BaseOperation<T, QueryStatus> {
|
|||||||
required super.retryDelay,
|
required super.retryDelay,
|
||||||
required this.queryBowl,
|
required this.queryBowl,
|
||||||
this.refetchOnMount,
|
this.refetchOnMount,
|
||||||
|
this.refetchOnReconnect,
|
||||||
this.refetchInterval,
|
this.refetchInterval,
|
||||||
this.enabled = true,
|
this.enabled = true,
|
||||||
T? initialData,
|
T? initialData,
|
||||||
@@ -117,6 +120,7 @@ class Query<T extends Object, Outside> extends BaseOperation<T, QueryStatus> {
|
|||||||
_externalData = externalData,
|
_externalData = externalData,
|
||||||
refetchInterval = options.refetchInterval,
|
refetchInterval = options.refetchInterval,
|
||||||
refetchOnMount = options.refetchOnMount,
|
refetchOnMount = options.refetchOnMount,
|
||||||
|
refetchOnReconnect = options.refetchOnReconnect,
|
||||||
super(
|
super(
|
||||||
status: QueryStatus.idle,
|
status: QueryStatus.idle,
|
||||||
cacheTime: options.cacheTime ?? const Duration(minutes: 5),
|
cacheTime: options.cacheTime ?? const Duration(minutes: 5),
|
||||||
@@ -137,7 +141,11 @@ class Query<T extends Object, Outside> extends BaseOperation<T, QueryStatus> {
|
|||||||
return Timer.periodic(
|
return Timer.periodic(
|
||||||
refetchInterval!,
|
refetchInterval!,
|
||||||
(_) async {
|
(_) async {
|
||||||
if (isStale) await refetch();
|
// only refetch if its connected to the internet or refetch will
|
||||||
|
// always result in error while there's no internet
|
||||||
|
if (isStale &&
|
||||||
|
isConnectedToInternet(await Connectivity().checkConnectivity()))
|
||||||
|
await refetch();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -278,6 +286,7 @@ class Query<T extends Object, Outside> extends BaseOperation<T, QueryStatus> {
|
|||||||
Duration? staleTime,
|
Duration? staleTime,
|
||||||
Duration? cacheTime,
|
Duration? cacheTime,
|
||||||
bool? refetchOnMount,
|
bool? refetchOnMount,
|
||||||
|
bool? refetchOnReconnect,
|
||||||
}) {
|
}) {
|
||||||
if (this.refetchInterval == null &&
|
if (this.refetchInterval == null &&
|
||||||
refetchInterval != null &&
|
refetchInterval != null &&
|
||||||
@@ -292,12 +301,14 @@ class Query<T extends Object, Outside> extends BaseOperation<T, QueryStatus> {
|
|||||||
staleTime != null) this._staleTime = staleTime;
|
staleTime != null) this._staleTime = staleTime;
|
||||||
if (this.refetchOnMount == null && refetchOnMount != null)
|
if (this.refetchOnMount == null && refetchOnMount != null)
|
||||||
this.refetchOnMount = refetchOnMount;
|
this.refetchOnMount = refetchOnMount;
|
||||||
|
if (this.refetchOnReconnect == null && refetchOnReconnect != null)
|
||||||
|
this.refetchOnReconnect = refetchOnReconnect;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<ValueKey<String>, Query> _dependencyQueries = {};
|
Map<ValueKey<String>, Query> _dependencyQueries = {};
|
||||||
|
|
||||||
/// only usable inside any task method
|
/// only usable inside [QueryJob.task] method
|
||||||
Query<T, Outside> dependOnQuery<T extends Object, Outside>(
|
Query<T, Outside> dependOnQuery<T extends Object, Outside>(
|
||||||
QueryJob<T, Outside> job, {
|
QueryJob<T, Outside> job, {
|
||||||
required Outside externalData,
|
required Outside externalData,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||||
import 'package:fl_query/src/models/query_job.dart';
|
import 'package:fl_query/src/models/query_job.dart';
|
||||||
import 'package:fl_query/src/mutation.dart';
|
import 'package:fl_query/src/mutation.dart';
|
||||||
import 'package:fl_query/src/query.dart';
|
import 'package:fl_query/src/query.dart';
|
||||||
@@ -14,16 +15,28 @@ class QueryBowlScope extends StatefulWidget {
|
|||||||
|
|
||||||
// refetching options
|
// refetching options
|
||||||
|
|
||||||
// refetch query when new query instance mounts
|
/// refetch query when new query instance mounts
|
||||||
final bool refetchOnMount;
|
final bool refetchOnMount;
|
||||||
// for desktop & web only
|
|
||||||
|
/// for desktop & web only
|
||||||
final bool refetchOnWindowFocus;
|
final bool refetchOnWindowFocus;
|
||||||
// for mobile only
|
|
||||||
|
/// for mobile only
|
||||||
final bool refetchOnApplicationResume;
|
final bool refetchOnApplicationResume;
|
||||||
// refetch when user's device reconnects to the internet after no being
|
|
||||||
// connected before
|
/// refetch when user's device reconnects to the internet after no being
|
||||||
|
/// connected before
|
||||||
final bool refetchOnReconnect;
|
final bool refetchOnReconnect;
|
||||||
|
|
||||||
|
/// the delay to call each query when user device reconnects to the
|
||||||
|
/// internet. Using a delay after each refetch so refetching all the
|
||||||
|
/// queries at once won't create high CPU spikes & also wouldn't violate
|
||||||
|
/// rate-limit
|
||||||
|
///
|
||||||
|
/// Though its recommended most of the time to use but it can be turned
|
||||||
|
/// off by setting passing [Duration.zero]
|
||||||
|
final Duration refetchOnReconnectDelay;
|
||||||
|
|
||||||
/// used for periodically checking if any query got stale.
|
/// used for periodically checking if any query got stale.
|
||||||
/// If none is supplied then half of the value of staleTime is used
|
/// If none is supplied then half of the value of staleTime is used
|
||||||
final Duration refetchInterval;
|
final Duration refetchInterval;
|
||||||
@@ -34,6 +47,7 @@ class QueryBowlScope extends StatefulWidget {
|
|||||||
this.refetchInterval = Duration.zero,
|
this.refetchInterval = Duration.zero,
|
||||||
this.refetchOnMount = false,
|
this.refetchOnMount = false,
|
||||||
this.refetchOnReconnect = true,
|
this.refetchOnReconnect = true,
|
||||||
|
this.refetchOnReconnectDelay = const Duration(milliseconds: 100),
|
||||||
this.refetchOnApplicationResume = true,
|
this.refetchOnApplicationResume = true,
|
||||||
this.refetchOnWindowFocus = true,
|
this.refetchOnWindowFocus = true,
|
||||||
Key? key,
|
Key? key,
|
||||||
@@ -47,16 +61,31 @@ class _QueryBowlScopeState extends State<QueryBowlScope> {
|
|||||||
late Set<Query> queries;
|
late Set<Query> queries;
|
||||||
late Set<Mutation> mutations;
|
late Set<Mutation> mutations;
|
||||||
|
|
||||||
|
StreamSubscription<ConnectivityResult>? _connectionStatusSubscription;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
queries = {};
|
queries = {};
|
||||||
mutations = {};
|
mutations = {};
|
||||||
|
|
||||||
|
_connectionStatusSubscription = Connectivity()
|
||||||
|
.onConnectivityChanged
|
||||||
|
.listen((ConnectivityResult result) async {
|
||||||
|
if (isConnectedToInternet(result)) {
|
||||||
|
for (final query in queries) {
|
||||||
|
if (query.refetchOnReconnect == false) continue;
|
||||||
|
await query.refetch();
|
||||||
|
await Future.delayed(widget.refetchOnReconnectDelay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_disposeUpdateListeners();
|
_disposeUpdateListeners();
|
||||||
|
_connectionStatusSubscription?.cancel();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,6 +195,7 @@ class _QueryBowlScopeState extends State<QueryBowlScope> {
|
|||||||
cacheTime: widget.cacheTime,
|
cacheTime: widget.cacheTime,
|
||||||
refetchInterval: widget.refetchInterval,
|
refetchInterval: widget.refetchInterval,
|
||||||
refetchOnMount: widget.refetchOnMount,
|
refetchOnMount: widget.refetchOnMount,
|
||||||
|
refetchOnReconnect: widget.refetchOnReconnect,
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -181,6 +211,7 @@ class QueryBowl extends InheritedWidget {
|
|||||||
|
|
||||||
final Duration? refetchInterval;
|
final Duration? refetchInterval;
|
||||||
final bool refetchOnMount;
|
final bool refetchOnMount;
|
||||||
|
final bool refetchOnReconnect;
|
||||||
|
|
||||||
final void Function<T extends Object, Outside>(Query<T, Outside> query)
|
final void Function<T extends Object, Outside>(Query<T, Outside> query)
|
||||||
_addQuery;
|
_addQuery;
|
||||||
@@ -206,6 +237,7 @@ class QueryBowl extends InheritedWidget {
|
|||||||
required this.removeQueries,
|
required this.removeQueries,
|
||||||
required this.clear,
|
required this.clear,
|
||||||
required this.refetchOnMount,
|
required this.refetchOnMount,
|
||||||
|
required this.refetchOnReconnect,
|
||||||
this.refetchInterval,
|
this.refetchInterval,
|
||||||
Key? key,
|
Key? key,
|
||||||
}) : _addQuery = addQuery,
|
}) : _addQuery = addQuery,
|
||||||
@@ -251,6 +283,7 @@ class QueryBowl extends InheritedWidget {
|
|||||||
options.staleTime ??= staleTime;
|
options.staleTime ??= staleTime;
|
||||||
options.cacheTime ??= cacheTime;
|
options.cacheTime ??= cacheTime;
|
||||||
options.refetchOnMount ??= refetchOnMount;
|
options.refetchOnMount ??= refetchOnMount;
|
||||||
|
options.refetchOnReconnect ??= refetchOnReconnect;
|
||||||
final query = Query<T, Outside>.fromOptions(
|
final query = Query<T, Outside>.fromOptions(
|
||||||
options,
|
options,
|
||||||
externalData: externalData,
|
externalData: externalData,
|
||||||
@@ -296,6 +329,7 @@ class QueryBowl extends InheritedWidget {
|
|||||||
staleTime: staleTime,
|
staleTime: staleTime,
|
||||||
refetchInterval: refetchInterval,
|
refetchInterval: refetchInterval,
|
||||||
refetchOnMount: refetchOnMount,
|
refetchOnMount: refetchOnMount,
|
||||||
|
refetchOnReconnect: refetchOnReconnect,
|
||||||
);
|
);
|
||||||
query.mount(key);
|
query.mount(key);
|
||||||
_addQuery<T, Outside>(query);
|
_addQuery<T, Outside>(query);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||||
import 'package:fl_query/src/query.dart';
|
import 'package:fl_query/src/query.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
@@ -41,3 +42,11 @@ bool isShallowEqual(Object obj1, Object obj2) {
|
|||||||
return obj1 == obj2;
|
return obj1 == obj2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isConnectedToInternet(ConnectivityResult result) {
|
||||||
|
return [
|
||||||
|
ConnectivityResult.ethernet,
|
||||||
|
ConnectivityResult.mobile,
|
||||||
|
ConnectivityResult.wifi,
|
||||||
|
].contains(result);
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ environment:
|
|||||||
dependencies:
|
dependencies:
|
||||||
async: ^2.8.2
|
async: ^2.8.2
|
||||||
collection: ^1.16.0
|
collection: ^1.16.0
|
||||||
|
connectivity_plus: ^2.3.5
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
uuid: ^3.0.6
|
uuid: ^3.0.6
|
||||||
|
|||||||
Reference in New Issue
Block a user