feat(QueryClientProvider): add config parameters and override-able client parameter
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user