diff --git a/packages/fl_query/.flutter-plugins b/packages/fl_query/.flutter-plugins index a59874f..379c920 100644 --- a/packages/fl_query/.flutter-plugins +++ b/packages/fl_query/.flutter-plugins @@ -1,6 +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=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6+1/ 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_web=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_web-1.2.3/ connectivity_plus_windows=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus_windows-1.2.2/ diff --git a/packages/fl_query/.flutter-plugins-dependencies b/packages/fl_query/.flutter-plugins-dependencies index ca26f71..a7e775e 100644 --- a/packages/fl_query/.flutter-plugins-dependencies +++ b/packages/fl_query/.flutter-plugins-dependencies @@ -1 +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-08-24 21:03:29.720419","version":"3.0.5"} \ No newline at end of file +{"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.6+1/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6+1/","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.3/","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-09-14 11:35:43.874010","version":"3.3.0"} \ No newline at end of file diff --git a/packages/fl_query/example/.flutter-plugins-dependencies b/packages/fl_query/example/.flutter-plugins-dependencies index bc68288..061cf3d 100644 --- a/packages/fl_query/example/.flutter-plugins-dependencies +++ b/packages/fl_query/example/.flutter-plugins-dependencies @@ -1 +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.6/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6/","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.3/","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-08-24 21:03:52.762936","version":"3.0.5"} \ No newline at end of file +{"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.6/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6/","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.3/","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-09-14 11:35:53.826188","version":"3.3.0"} \ No newline at end of file diff --git a/packages/fl_query/example/android/local.properties b/packages/fl_query/example/android/local.properties index d22f419..561f207 100644 --- a/packages/fl_query/example/android/local.properties +++ b/packages/fl_query/example/android/local.properties @@ -1,2 +1,5 @@ -sdk.dir=/opt/android-sdk -flutter.sdk=/home/krtirtho/fvm/versions/3.0.5 \ No newline at end of file +sdk.dir=/home/krtirtho/Android/Sdk +flutter.sdk=/opt/flutter +flutter.buildMode=debug +flutter.versionName=1.0.0 +flutter.versionCode=1 \ No newline at end of file diff --git a/packages/fl_query/example/lib/components/basic_infinite_query.dart b/packages/fl_query/example/lib/components/basic_infinite_query.dart index b8b5524..3985b45 100644 --- a/packages/fl_query/example/lib/components/basic_infinite_query.dart +++ b/packages/fl_query/example/lib/components/basic_infinite_query.dart @@ -1,7 +1,6 @@ import 'dart:convert'; import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'package:fl_query/fl_query.dart'; import 'package:http/http.dart' as http; @@ -49,9 +48,18 @@ class BasicInfiniteQueryExample extends StatelessWidget { ), Align( alignment: Alignment.bottomRight, - child: IconButton( - icon: const Icon(Icons.get_app_rounded), - onPressed: () => infiniteQuery.fetchNextPage(), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + IconButton( + icon: const Icon(Icons.refresh_rounded), + onPressed: () => infiniteQuery.refetchPages(), + ), + IconButton( + icon: const Icon(Icons.get_app_rounded), + onPressed: () => infiniteQuery.fetchNextPage(), + ), + ], ), ), ], diff --git a/packages/fl_query/example/linux/flutter/ephemeral/generated_config.cmake b/packages/fl_query/example/linux/flutter/ephemeral/generated_config.cmake index 2bf6219..7b6158f 100644 --- a/packages/fl_query/example/linux/flutter/ephemeral/generated_config.cmake +++ b/packages/fl_query/example/linux/flutter/ephemeral/generated_config.cmake @@ -1,10 +1,16 @@ # Generated code do not commit. -file(TO_CMAKE_PATH "/home/krtirtho/fvm/versions/3.0.5" FLUTTER_ROOT) +file(TO_CMAKE_PATH "/opt/flutter" FLUTTER_ROOT) file(TO_CMAKE_PATH "/home/krtirtho/dev/fl-query/packages/fl_query/example" PROJECT_DIR) +set(FLUTTER_VERSION "1.0.0+1" PARENT_SCOPE) +set(FLUTTER_VERSION_MAJOR 1 PARENT_SCOPE) +set(FLUTTER_VERSION_MINOR 0 PARENT_SCOPE) +set(FLUTTER_VERSION_PATCH 0 PARENT_SCOPE) +set(FLUTTER_VERSION_BUILD 1 PARENT_SCOPE) + # Environment variables to pass to tool_backend.sh list(APPEND FLUTTER_TOOL_ENVIRONMENT - "FLUTTER_ROOT=/home/krtirtho/fvm/versions/3.0.5" + "FLUTTER_ROOT=/opt/flutter" "PROJECT_DIR=/home/krtirtho/dev/fl-query/packages/fl_query/example" "DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==" "DART_OBFUSCATION=false" diff --git a/packages/fl_query/example/linux/flutter/ephemeral/icudtl.dat b/packages/fl_query/example/linux/flutter/ephemeral/icudtl.dat index d733c28..720a5c7 100644 Binary files a/packages/fl_query/example/linux/flutter/ephemeral/icudtl.dat and b/packages/fl_query/example/linux/flutter/ephemeral/icudtl.dat differ diff --git a/packages/fl_query/example/linux/flutter/ephemeral/libflutter_linux_gtk.so b/packages/fl_query/example/linux/flutter/ephemeral/libflutter_linux_gtk.so index 9cae4b1..6ae4b7d 100644 Binary files a/packages/fl_query/example/linux/flutter/ephemeral/libflutter_linux_gtk.so and b/packages/fl_query/example/linux/flutter/ephemeral/libflutter_linux_gtk.so differ diff --git a/packages/fl_query/example/pubspec.lock b/packages/fl_query/example/pubspec.lock index 963e39f..7fc7a76 100644 --- a/packages/fl_query/example/pubspec.lock +++ b/packages/fl_query/example/pubspec.lock @@ -14,7 +14,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" boolean_selector: dependency: transitive description: @@ -28,21 +28,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.2.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: @@ -119,7 +112,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" ffi: dependency: transitive description: @@ -197,21 +190,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" + version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" nm: dependency: transitive description: @@ -225,7 +218,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" petitparser: dependency: transitive description: @@ -240,6 +233,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.2" + queue: + dependency: transitive + description: + name: queue + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0+1" sky_engine: dependency: transitive description: flutter @@ -258,7 +258,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.2" + version: "1.9.0" stack_trace: dependency: transitive description: @@ -279,21 +279,21 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.9" + version: "0.4.12" typed_data: dependency: transitive description: diff --git a/packages/fl_query/lib/src/base_query.dart b/packages/fl_query/lib/src/base_query.dart index 6e99cce..0ee985c 100644 --- a/packages/fl_query/lib/src/base_query.dart +++ b/packages/fl_query/lib/src/base_query.dart @@ -71,7 +71,7 @@ abstract class BaseQuery if (onError != null) _onErrorListeners.add(onError); if (refetchInterval != null && refetchInterval != Duration.zero) { - _refetchIntervalTimer = _createRefetchTimer(); + _refetchIntervalTimer = createRefetchTimer(); } } // all getters & setters @@ -79,16 +79,8 @@ abstract class BaseQuery Outside get externalData => _externalData; Outside? get prevUsedExternalData => _prevUsedExternalData; - Timer _createRefetchTimer() { - return Timer.periodic( - refetchInterval!, - (_) async { - // only refetch if its connected to the internet or refetch will - // always result in error while there's no internet - if (isStale && await isInternetConnected()) await refetch(); - }, - ); - } + @protected + Timer createRefetchTimer(); /// Calls the task function & doesn't check if there's already /// cached data available @@ -205,7 +197,9 @@ abstract class BaseQuery return await execute().then((_) => data); } + @protected FutureOr setData(); + @protected void setError(dynamic); /// Sets the [externalData] from outside of the query @@ -251,7 +245,7 @@ abstract class BaseQuery refetchInterval != Duration.zero) { this.refetchInterval = refetchInterval; _refetchIntervalTimer?.cancel(); - _refetchIntervalTimer = _createRefetchTimer(); + _refetchIntervalTimer = createRefetchTimer(); } if (this.cacheTime == Duration(minutes: 5) && cacheTime != null) this.cacheTime = cacheTime; diff --git a/packages/fl_query/lib/src/infinite_query.dart b/packages/fl_query/lib/src/infinite_query.dart index e8b323c..a7f9025 100644 --- a/packages/fl_query/lib/src/infinite_query.dart +++ b/packages/fl_query/lib/src/infinite_query.dart @@ -4,6 +4,8 @@ import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:fl_query/src/base_query.dart'; import 'package:fl_query/src/models/infinite_query_job.dart'; import 'package:fl_query/src/query.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:queue/queue.dart'; typedef InfiniteQueryTaskFunction @@ -91,6 +93,19 @@ class InfiniteQuery List get errors => error?.values.toList() ?? []; List get pages => data?.values.toList() ?? []; + @override + @protected + Timer createRefetchTimer() { + return Timer.periodic( + refetchInterval!, + (_) async { + // only refetch if its connected to the internet or refetch will + // always result in error while there's no internet + if (isStale && await isInternetConnected()) await refetchPages(); + }, + ); + } + Future fetchNextPage([ InfiniteQueryPageParamFunction? getNextPageParam, ]) async { @@ -110,10 +125,11 @@ class InfiniteQuery _hasNextPage = false; notifyListeners(); return null; + } else { + _hasNextPage = true; + _currentParam = nextParam; + return await refetch().then((data) => data?[_currentParam]); } - _hasNextPage = true; - _currentParam = nextParam; - return await refetch().then((data) => data?[_currentParam]); } finally { _isFetchingNextPage = false; notifyListeners(); @@ -154,11 +170,53 @@ class InfiniteQuery } } + Future> refetchPages([ + bool Function(T? page, int index, List allPages)? selector, + ]) async { + if (isFetchingNextPage || + isFetchingPreviousPage || + isLoading || + isRefetching) return []; + final refetchedPages = []; + final queue = Queue(); + for (final entry in data?.entries.toList() ?? >[]) { + final page = entry.value; + final selected = selector?.call(page, pages.indexOf(page), pages) ?? true; + if (!selected) continue; + _currentParam = entry.key; + queue.add( + () async { + final s = await refetch(); + if (s?[_currentParam] != null) { + refetchedPages.add(s![_currentParam]!); + } + }, + ); + } + await queue.onComplete; + return refetchedPages; + } + @override // TODO: implement debugLabel String get debugLabel => "InfiniteQuery($queryKey)"; @override + void mount(ValueKey uKey) { + super.mount(uKey); + + /// refetching on mount if it's set to true + /// also checking if the is stale or not + /// no need to refetch a valid query for no reason + if (refetchOnMount == true && isStale) { + this.isInternetConnected().then((isConnected) async { + if (isConnected) await refetchPages(); + }); + } + } + + @override + @protected void setData() async { if (data == null) data = Map(); data?[_currentParam] = await task( @@ -169,6 +227,7 @@ class InfiniteQuery } @override + @protected void setError(specError) { if (error is! Map) error = Map(); error?[_currentParam] = specError; diff --git a/packages/fl_query/lib/src/infinite_query_builder.dart b/packages/fl_query/lib/src/infinite_query_builder.dart index 64ab2c8..2b2bc33 100644 --- a/packages/fl_query/lib/src/infinite_query_builder.dart +++ b/packages/fl_query/lib/src/infinite_query_builder.dart @@ -48,14 +48,77 @@ class _InfiniteQueryBuilderState extends BaseQuery { queryKey: options.queryKey, ); + @override + Timer createRefetchTimer() { + return Timer.periodic( + refetchInterval!, + (_) async { + // only refetch if its connected to the internet or refetch will + // always result in error while there's no internet + if (isStale && await isInternetConnected()) await refetch(); + }, + ); + } + /// can be used to update the data manually. Can be useful when used /// together with mutations to perform optimistic updates or manual data /// updates diff --git a/packages/fl_query/lib/src/query_bowl.dart b/packages/fl_query/lib/src/query_bowl.dart index c292d91..bacb2b4 100644 --- a/packages/fl_query/lib/src/query_bowl.dart +++ b/packages/fl_query/lib/src/query_bowl.dart @@ -114,6 +114,12 @@ class _QueryBowlScopeState extends State { await query.refetch(); await Future.delayed(widget.refetchOnReconnectDelay); } + for (final infiniteQuery in infiniteQueries) { + if (infiniteQuery.refetchOnReconnect == false || + !infiniteQuery.enabled) continue; + await infiniteQuery.refetchPages(); + await Future.delayed(widget.refetchOnReconnectDelay); + } } }); } @@ -169,10 +175,10 @@ class _QueryBowlScopeState extends State { // basically garbage collecting queries setState(() { infiniteQueries = Set.from( - // infiniteQuery.isInactive - // ? infiniteQueries.where((el) => el.queryKey != infiniteQuery.queryKey) - // : infiniteQuery, - infiniteQueries, + infiniteQuery.isInactive + ? infiniteQueries + .where((el) => el.queryKey != infiniteQuery.queryKey) + : infiniteQueries, ); }); }); @@ -350,25 +356,25 @@ class QueryBowl extends InheritedWidget { return query; } - // InfiniteQuery _createInfiniteQueryWithDefaults< - // T extends Object, Outside, PageParam extends Object>( - // InfiniteQueryJob options, - // Outside externalData, - // ) { - // final query = InfiniteQuery.fromOptions( - // options, - // externalData: externalData, - // queryBowl: this, - // ); - // query.updateDefaultOptions( - // cacheTime: cacheTime, - // staleTime: staleTime, - // refetchInterval: refetchInterval, - // refetchOnMount: refetchOnMount, - // refetchOnReconnect: refetchOnReconnect, - // ); - // return query; - // } + InfiniteQuery _createInfiniteQueryWithDefaults< + T extends Object, Outside, PageParam extends Object>( + InfiniteQueryJob options, + Outside externalData, + ) { + final infiniteQuery = InfiniteQuery.fromOptions( + options, + externalData: externalData, + queryBowl: this, + ); + infiniteQuery.updateDefaultOptions( + cacheTime: cacheTime, + staleTime: staleTime, + refetchInterval: refetchInterval, + refetchOnMount: refetchOnMount, + refetchOnReconnect: refetchOnReconnect, + ); + return infiniteQuery; + } Future prefetchQuery( QueryJob options, { @@ -451,18 +457,15 @@ class QueryBowl extends InheritedWidget { // mounting the widget that is using the query in the prevQuery return prevInfiniteQuery; } - // _createQueryWithDefaults( - // infiniteQueryJob, - // externalData, - // ); - final infiniteQuery = InfiniteQuery.fromOptions( + + final infiniteQuery = + _createInfiniteQueryWithDefaults( infiniteQueryJob, - externalData: externalData, - queryBowl: this, + externalData, ); - // if (onData != null) infiniteQuery.addDataListener(onData); - // if (onError != null) infiniteQuery.addErrorListener(onError); - // infiniteQuery.mount(key); + if (onData != null) infiniteQuery.addDataListener(onData); + if (onError != null) infiniteQuery.addErrorListener(onError); + infiniteQuery.mount(key); _addInfiniteQuery(infiniteQuery); return infiniteQuery; } diff --git a/packages/fl_query/lib/src/query_builder.dart b/packages/fl_query/lib/src/query_builder.dart index b4ea9fc..6ecbfb2 100644 --- a/packages/fl_query/lib/src/query_builder.dart +++ b/packages/fl_query/lib/src/query_builder.dart @@ -57,7 +57,11 @@ class _QueryBuilderState ); final hasExternalDataChanged = query!.externalData != null && query!.prevUsedExternalData != null && - !isShallowEqual(query!.externalData!, query!.prevUsedExternalData!); + !isShallowEqual( + query!.externalData!, + query!.prevUsedExternalData!, + ); + if (query!.fetched && hasExternalDataChanged) { await query!.refetch(); } else if (!query!.fetched) { diff --git a/packages/fl_query/pubspec.yaml b/packages/fl_query/pubspec.yaml index 6eab676..52e61b7 100644 --- a/packages/fl_query/pubspec.yaml +++ b/packages/fl_query/pubspec.yaml @@ -17,6 +17,7 @@ dependencies: connectivity_plus: ^2.3.5 flutter: sdk: flutter + queue: ^3.1.0+1 uuid: ^3.0.6 dev_dependencies: diff --git a/packages/fl_query_hooks/.flutter-plugins b/packages/fl_query_hooks/.flutter-plugins index c789221..379c920 100644 --- a/packages/fl_query_hooks/.flutter-plugins +++ b/packages/fl_query_hooks/.flutter-plugins @@ -1,5 +1,5 @@ # 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.6/ +connectivity_plus=/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6+1/ 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.3/ diff --git a/packages/fl_query_hooks/.flutter-plugins-dependencies b/packages/fl_query_hooks/.flutter-plugins-dependencies index a50eb54..87d8731 100644 --- a/packages/fl_query_hooks/.flutter-plugins-dependencies +++ b/packages/fl_query_hooks/.flutter-plugins-dependencies @@ -1 +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.6/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6/","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.3/","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-08-16 21:50:27.976582","version":"3.0.5"} \ No newline at end of file +{"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.6+1/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6+1/","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.3/","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-09-14 11:35:42.984387","version":"3.3.0"} \ No newline at end of file diff --git a/packages/fl_query_hooks/example/.flutter-plugins-dependencies b/packages/fl_query_hooks/example/.flutter-plugins-dependencies index 693d931..e40aedb 100644 --- a/packages/fl_query_hooks/example/.flutter-plugins-dependencies +++ b/packages/fl_query_hooks/example/.flutter-plugins-dependencies @@ -1 +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.6/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6/","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.3/","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-08-16 21:50:30.683860","version":"3.0.5"} \ No newline at end of file +{"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.6/","native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/home/krtirtho/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6/","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.3/","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-09-14 11:35:47.051873","version":"3.3.0"} \ No newline at end of file diff --git a/packages/fl_query_hooks/example/pubspec.lock b/packages/fl_query_hooks/example/pubspec.lock index bb5bc48..92718bb 100644 --- a/packages/fl_query_hooks/example/pubspec.lock +++ b/packages/fl_query_hooks/example/pubspec.lock @@ -14,7 +14,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" boolean_selector: dependency: transitive description: @@ -28,21 +28,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.2.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: @@ -119,7 +112,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" ffi: dependency: transitive description: @@ -204,21 +197,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" + version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" nm: dependency: transitive description: @@ -232,7 +225,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" petitparser: dependency: transitive description: @@ -247,6 +240,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.2" + queue: + dependency: transitive + description: + name: queue + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0+1" sky_engine: dependency: transitive description: flutter @@ -258,7 +258,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.2" + version: "1.9.0" stack_trace: dependency: transitive description: @@ -279,21 +279,21 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.9" + version: "0.4.12" typed_data: dependency: transitive description: