From a85434a4db6d4b4f53a0cb616891759127e30b1c Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Thu, 16 Feb 2023 12:48:19 +0600 Subject: [PATCH] fix: not updating queryFn on create query's old query and checking stale status after updating queryFn instead of storing the status before --- packages/fl_query/lib/src/core/client.dart | 1 + packages/fl_query/lib/src/core/query.dart | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/fl_query/lib/src/core/client.dart b/packages/fl_query/lib/src/core/client.dart index ea10f17..3baf9c7 100644 --- a/packages/fl_query/lib/src/core/client.dart +++ b/packages/fl_query/lib/src/core/client.dart @@ -35,6 +35,7 @@ class QueryClient { ), ) .cast(); + query.updateQueryFn(queryFn); cache.addQuery(query); return query; } diff --git a/packages/fl_query/lib/src/core/query.dart b/packages/fl_query/lib/src/core/query.dart index 0ad8f26..5043dce 100644 --- a/packages/fl_query/lib/src/core/query.dart +++ b/packages/fl_query/lib/src/core/query.dart @@ -153,8 +153,12 @@ class Query } void updateQueryFn(QueryFn queryFn) { + if (state.queryFn == queryFn) return; + // updatedAt is updated with copyWith so storing it + // here to check if the query is stale later + final stale = state.isStale; state = state.copyWith(queryFn: queryFn); - if (state.isStale || refreshConfig.refreshOnQueryFnChange) { + if (stale || refreshConfig.refreshOnQueryFnChange) { refresh(); } }