From f8895e338141488e5bce4401c80b491688932085 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sun, 12 Mar 2023 11:03:12 +0600 Subject: [PATCH] feat(QueryClientProvider): add config parameters and override-able client parameter --- packages/fl_query/lib/src/core/provider.dart | 41 +++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/fl_query/lib/src/core/provider.dart b/packages/fl_query/lib/src/core/provider.dart index d798eb7..80457d3 100644 --- a/packages/fl_query/lib/src/core/provider.dart +++ b/packages/fl_query/lib/src/core/provider.dart @@ -1,10 +1,49 @@ +import 'package:fl_query/src/collections/default_configs.dart'; +import 'package:fl_query/src/core/cache.dart'; import 'package:fl_query/src/core/client.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; class QueryClientProvider extends InheritedWidget { final QueryClient client; - QueryClientProvider({required super.child}) : client = QueryClient(); + QueryClientProvider({ + super.key, + required super.child, + QueryClient? client, + QueryCache? cache, + Duration cacheDuration = DefaultConstants.cacheDuration, + int? maxRetries, + Duration? retryDelay, + Duration? staleDuration, + Duration? refreshInterval, + bool? refreshOnMount, + bool? refreshOnQueryFnChange, + }) : assert((client == null && cache != null) || cache == null), + assert((client == null && maxRetries != null) || maxRetries == null), + assert((client == null && retryDelay != null) || retryDelay == null), + assert( + (client == null && staleDuration != null) || staleDuration == null), + assert((client == null && refreshInterval != null) || + refreshInterval == null), + assert((client == null && refreshOnMount != null) || + refreshOnMount == null), + assert((client == null && refreshOnQueryFnChange != null) || + refreshOnQueryFnChange == null), + assert( + (client == null && cacheDuration != DefaultConstants.cacheDuration) || + cacheDuration == DefaultConstants.cacheDuration, + ), + client = client ?? + QueryClient( + cache: cache, + cacheDuration: cacheDuration, + maxRetries: maxRetries, + retryDelay: retryDelay, + staleDuration: staleDuration, + refreshInterval: refreshInterval, + refreshOnMount: refreshOnMount, + refreshOnQueryFnChange: refreshOnQueryFnChange, + ); @override bool updateShouldNotify(covariant QueryClientProvider oldWidget) {