refactor: remove KyeType and use String for queryKey and mutationKey
This commit is contained in:
@@ -21,8 +21,7 @@ class _InfiniteQueryPageWidgetState extends State<InfiniteQueryPageWidget> {
|
||||
super.initState();
|
||||
controller.addListener(() async {
|
||||
if (controller.position.pixels == controller.position.maxScrollExtent) {
|
||||
final query = QueryClient.of(context)
|
||||
.getInfiniteQuery(const ValueKey("products"));
|
||||
final query = QueryClient.of(context).getInfiniteQuery("products");
|
||||
await query?.fetchNext();
|
||||
}
|
||||
});
|
||||
@@ -40,8 +39,8 @@ class _InfiniteQueryPageWidgetState extends State<InfiniteQueryPageWidget> {
|
||||
appBar: AppBar(
|
||||
title: const Text('Infinite Query'),
|
||||
),
|
||||
floatingActionButton: InfiniteQueryListenable(const ValueKey("products"),
|
||||
builder: (context, query) {
|
||||
floatingActionButton:
|
||||
InfiniteQueryListenable("products", builder: (context, query) {
|
||||
return FloatingActionButton(
|
||||
onPressed: () {
|
||||
query?.fetchNext();
|
||||
@@ -49,8 +48,8 @@ class _InfiniteQueryPageWidgetState extends State<InfiniteQueryPageWidget> {
|
||||
child: Text(query?.pages.length.toString() ?? "-69"),
|
||||
);
|
||||
}),
|
||||
body: InfiniteQueryBuilder<PagedProducts, ClientException, String, int>(
|
||||
const ValueKey("products"),
|
||||
body: InfiniteQueryBuilder<PagedProducts, ClientException, int>(
|
||||
"products",
|
||||
(page) async {
|
||||
final res = await get(Uri.parse(
|
||||
"https://dummyjson.com/products?limit=10&skip=${page * 10}",
|
||||
|
||||
@@ -35,9 +35,9 @@ class _MutationPageState extends State<MutationPage> {
|
||||
appBar: AppBar(
|
||||
title: const Text('Mutation'),
|
||||
),
|
||||
body: MutationBuilder<Map<String, dynamic>, dynamic, String,
|
||||
Map<String, dynamic>, dynamic>(
|
||||
const ValueKey('sign-up'),
|
||||
body: MutationBuilder<Map<String, dynamic>, dynamic, Map<String, dynamic>,
|
||||
dynamic>(
|
||||
'sign-up',
|
||||
(variables) {
|
||||
return Future.delayed(
|
||||
const Duration(seconds: 1),
|
||||
@@ -56,9 +56,7 @@ class _MutationPageState extends State<MutationPage> {
|
||||
print('onData: $data');
|
||||
print('recoveryData: $recoveryData');
|
||||
},
|
||||
refreshQueries: const [
|
||||
ValueKey('hello'),
|
||||
],
|
||||
refreshQueries: const ['hello'],
|
||||
builder: (context, mutation) {
|
||||
if (mutation.hasData) {
|
||||
return ListView(
|
||||
|
||||
@@ -13,8 +13,8 @@ class QueryPage extends StatelessWidget {
|
||||
appBar: AppBar(
|
||||
title: const Text('Query'),
|
||||
),
|
||||
floatingActionButton: QueryListenable<String, dynamic, String>(
|
||||
const ValueKey('hello'), builder: (context, query) {
|
||||
floatingActionButton:
|
||||
QueryListenable<String, dynamic>('hello', builder: (context, query) {
|
||||
if (query == null) {
|
||||
return const SizedBox();
|
||||
}
|
||||
@@ -25,8 +25,8 @@ class QueryPage extends StatelessWidget {
|
||||
child: Text(query.data ?? 'No Data'),
|
||||
);
|
||||
}),
|
||||
body: QueryBuilder<String, dynamic, String>(
|
||||
const ValueKey('hello'),
|
||||
body: QueryBuilder<String, dynamic>(
|
||||
'hello',
|
||||
() {
|
||||
return Future.delayed(
|
||||
const Duration(seconds: 6), () => 'Hello World! $value');
|
||||
|
||||
@@ -16,8 +16,8 @@ class QueryClient {
|
||||
|
||||
QueryClient({QueryCache? cache}) : this.cache = cache ?? QueryCache();
|
||||
|
||||
Query<DataType, ErrorType, KeyType> createQuery<DataType, ErrorType, KeyType>(
|
||||
ValueKey<KeyType> key,
|
||||
Query<DataType, ErrorType> createQuery<DataType, ErrorType>(
|
||||
String key,
|
||||
QueryFn<DataType> queryFn, {
|
||||
DataType? initial,
|
||||
RetryConfig retryConfig = DefaultConstants.retryConfig,
|
||||
@@ -27,7 +27,7 @@ class QueryClient {
|
||||
final query = cache.queries
|
||||
.firstWhere(
|
||||
(query) => query.key == key,
|
||||
orElse: () => Query<DataType, ErrorType, KeyType>(
|
||||
orElse: () => Query<DataType, ErrorType>(
|
||||
key,
|
||||
queryFn,
|
||||
initial: initial,
|
||||
@@ -36,21 +36,21 @@ class QueryClient {
|
||||
jsonConfig: jsonConfig,
|
||||
),
|
||||
)
|
||||
.cast<DataType, ErrorType, KeyType>();
|
||||
.cast<DataType, ErrorType>();
|
||||
query.updateQueryFn(queryFn);
|
||||
cache.addQuery(query);
|
||||
return query;
|
||||
}
|
||||
|
||||
Future<DataType?> fetchQuery<DataType, ErrorType, KeyType>(
|
||||
ValueKey<KeyType> key,
|
||||
Future<DataType?> fetchQuery<DataType, ErrorType>(
|
||||
String key,
|
||||
QueryFn<DataType> queryFn, {
|
||||
DataType? initial,
|
||||
RetryConfig retryConfig = DefaultConstants.retryConfig,
|
||||
RefreshConfig refreshConfig = DefaultConstants.refreshConfig,
|
||||
JsonConfig<DataType>? jsonConfig,
|
||||
}) async {
|
||||
final query = createQuery<DataType, ErrorType, KeyType>(
|
||||
final query = createQuery<DataType, ErrorType>(
|
||||
key,
|
||||
queryFn,
|
||||
initial: initial,
|
||||
@@ -61,33 +61,33 @@ class QueryClient {
|
||||
return await query.fetch();
|
||||
}
|
||||
|
||||
Query<DataType, ErrorType, KeyType>? getQuery<DataType, ErrorType, KeyType>(
|
||||
ValueKey<KeyType> key) {
|
||||
Query<DataType, ErrorType>? getQuery<DataType, ErrorType>(
|
||||
String key,
|
||||
) {
|
||||
return cache.queries
|
||||
.firstWhereOrNull((query) => query.key == key)
|
||||
?.cast<DataType, ErrorType, KeyType>();
|
||||
?.cast<DataType, ErrorType>();
|
||||
}
|
||||
|
||||
List<Query> getQueries(List<ValueKey> keys) {
|
||||
List<Query> getQueries(List<String> keys) {
|
||||
return cache.queries.where((query) => keys.contains(query.key)).toList();
|
||||
}
|
||||
|
||||
Future<DataType?> refreshQuery<DataType, ErrorType, KeyType>(
|
||||
ValueKey<KeyType> key,
|
||||
Future<DataType?> refreshQuery<DataType, ErrorType>(String key,
|
||||
{DataType? initial}) async {
|
||||
final query = getQuery<DataType, ErrorType, KeyType>(key);
|
||||
final query = getQuery<DataType, ErrorType>(key);
|
||||
if (query == null) return null;
|
||||
return await query.refresh();
|
||||
}
|
||||
|
||||
Future<List> refreshQueries(List<ValueKey> keys) async {
|
||||
Future<List> refreshQueries(List<String> keys) async {
|
||||
final queries = getQueries(keys);
|
||||
return await Future.wait(queries.map((query) => query.refresh()));
|
||||
}
|
||||
|
||||
InfiniteQuery<DataType, ErrorType, KeyType, PageType>
|
||||
createInfiniteQuery<DataType, ErrorType, KeyType, PageType>(
|
||||
ValueKey<KeyType> key,
|
||||
InfiniteQuery<DataType, ErrorType, PageType>
|
||||
createInfiniteQuery<DataType, ErrorType, PageType>(
|
||||
String key,
|
||||
InfiniteQueryFn<DataType, PageType> queryFn, {
|
||||
required InfiniteQueryNextPage<DataType, PageType> nextPage,
|
||||
required PageType initialParam,
|
||||
@@ -98,7 +98,7 @@ class QueryClient {
|
||||
final query = cache.infiniteQueries
|
||||
.firstWhere(
|
||||
(query) => query.key == key,
|
||||
orElse: () => InfiniteQuery<DataType, ErrorType, KeyType, PageType>(
|
||||
orElse: () => InfiniteQuery<DataType, ErrorType, PageType>(
|
||||
key,
|
||||
queryFn,
|
||||
nextPage: nextPage,
|
||||
@@ -108,20 +108,20 @@ class QueryClient {
|
||||
jsonConfig: jsonConfig,
|
||||
),
|
||||
)
|
||||
.cast<DataType, ErrorType, KeyType, PageType>();
|
||||
.cast<DataType, ErrorType, PageType>();
|
||||
query.updateQueryFn(queryFn);
|
||||
cache.addInfiniteQuery(query);
|
||||
return query;
|
||||
}
|
||||
|
||||
Future<DataType?> fetchInfiniteQuery<DataType, ErrorType, KeyType, PageType>(
|
||||
ValueKey<KeyType> key, InfiniteQueryFn<DataType, PageType> queryFn,
|
||||
Future<DataType?> fetchInfiniteQuery<DataType, ErrorType, PageType>(
|
||||
String key, InfiniteQueryFn<DataType, PageType> queryFn,
|
||||
{required InfiniteQueryNextPage<DataType, PageType> nextPage,
|
||||
required PageType initialParam,
|
||||
RetryConfig retryConfig = DefaultConstants.retryConfig,
|
||||
RefreshConfig refreshConfig = DefaultConstants.refreshConfig,
|
||||
JsonConfig<DataType>? jsonConfig}) async {
|
||||
final query = createInfiniteQuery<DataType, ErrorType, KeyType, PageType>(
|
||||
final query = createInfiniteQuery<DataType, ErrorType, PageType>(
|
||||
key,
|
||||
queryFn,
|
||||
nextPage: nextPage,
|
||||
@@ -133,85 +133,83 @@ class QueryClient {
|
||||
return await query.fetch();
|
||||
}
|
||||
|
||||
InfiniteQuery<DataType, ErrorType, KeyType, PageType>?
|
||||
getInfiniteQuery<DataType, ErrorType, KeyType, PageType>(
|
||||
ValueKey<KeyType> key) {
|
||||
InfiniteQuery<DataType, ErrorType, PageType>?
|
||||
getInfiniteQuery<DataType, ErrorType, PageType>(String key) {
|
||||
return cache.infiniteQueries
|
||||
.firstWhereOrNull((query) => query.key == key)
|
||||
?.cast<DataType, ErrorType, KeyType, PageType>();
|
||||
?.cast<DataType, ErrorType, PageType>();
|
||||
}
|
||||
|
||||
List<InfiniteQuery> getInfiniteQueries(List<ValueKey> keys) {
|
||||
List<InfiniteQuery> getInfiniteQueries(List<String> keys) {
|
||||
return cache.infiniteQueries
|
||||
.where((query) => keys.contains(query.key))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<DataType?>
|
||||
refreshInfiniteQuery<DataType, ErrorType, KeyType, PageType>(
|
||||
ValueKey<KeyType> key,
|
||||
[PageType? page]) async {
|
||||
final query = getInfiniteQuery<DataType, ErrorType, KeyType, PageType>(key);
|
||||
Future<DataType?> refreshInfiniteQuery<DataType, ErrorType, PageType>(
|
||||
String key,
|
||||
[PageType? page]) async {
|
||||
final query = getInfiniteQuery<DataType, ErrorType, PageType>(key);
|
||||
if (query == null) return null;
|
||||
return await query.refresh(page);
|
||||
}
|
||||
|
||||
Future<List<DataType>?>
|
||||
refreshInfiniteQueryAllPages<DataType, ErrorType, KeyType, PageType>(
|
||||
ValueKey<KeyType> key) async {
|
||||
final query = getInfiniteQuery<DataType, ErrorType, KeyType, PageType>(key);
|
||||
refreshInfiniteQueryAllPages<DataType, ErrorType, PageType>(
|
||||
String key) async {
|
||||
final query = getInfiniteQuery<DataType, ErrorType, PageType>(key);
|
||||
if (query == null) return [];
|
||||
return await query.refreshAll();
|
||||
}
|
||||
|
||||
Future<List> refreshInfiniteQueries(List<ValueKey> keys) async {
|
||||
Future<List> refreshInfiniteQueries(List<String> keys) async {
|
||||
final queries = getInfiniteQueries(keys);
|
||||
return await Future.wait(queries.map((query) => query.refresh()));
|
||||
}
|
||||
|
||||
Future<Map<ValueKey, List?>> refreshInfiniteQueriesAllPages(
|
||||
List<ValueKey> keys) async {
|
||||
Future<Map<String, List?>> refreshInfiniteQueriesAllPages(
|
||||
List<String> keys) async {
|
||||
final queries = getInfiniteQueries(keys);
|
||||
return await Future.wait(queries.map(
|
||||
(query) async => MapEntry(query.key, await query.refreshAll())))
|
||||
.then((qs) => Map.fromEntries(qs));
|
||||
}
|
||||
|
||||
Mutation<DataType, ErrorType, KeyType, VariablesType>
|
||||
createMutation<DataType, ErrorType, KeyType, VariablesType>(
|
||||
ValueKey<KeyType> key,
|
||||
Mutation<DataType, ErrorType, VariablesType>
|
||||
createMutation<DataType, ErrorType, VariablesType>(
|
||||
String key,
|
||||
MutationFn<DataType, VariablesType> mutationFn, {
|
||||
RetryConfig retryConfig = DefaultConstants.retryConfig,
|
||||
}) {
|
||||
final mutation = cache.mutations
|
||||
.firstWhere(
|
||||
(query) => query.key == key,
|
||||
orElse: () => Mutation<DataType, ErrorType, KeyType, VariablesType>(
|
||||
orElse: () => Mutation<DataType, ErrorType, VariablesType>(
|
||||
key,
|
||||
mutationFn,
|
||||
retryConfig: retryConfig,
|
||||
),
|
||||
)
|
||||
.cast<DataType, ErrorType, KeyType, VariablesType>();
|
||||
.cast<DataType, ErrorType, VariablesType>();
|
||||
|
||||
mutation.updateMutationFn(mutationFn);
|
||||
cache.addMutation(mutation);
|
||||
return mutation;
|
||||
}
|
||||
|
||||
Future<DataType?> mutateMutation<DataType, ErrorType, KeyType, VariablesType>(
|
||||
ValueKey<KeyType> key,
|
||||
Future<DataType?> mutateMutation<DataType, ErrorType, VariablesType>(
|
||||
String key,
|
||||
VariablesType variables, {
|
||||
MutationFn<DataType, VariablesType>? mutationFn,
|
||||
RetryConfig retryConfig = DefaultConstants.retryConfig,
|
||||
List<ValueKey> refreshQueries = const [],
|
||||
List<ValueKey> refreshInfiniteQueries = const [],
|
||||
List<String> refreshQueries = const [],
|
||||
List<String> refreshInfiniteQueries = const [],
|
||||
}) async {
|
||||
final mutation = getMutation<DataType, ErrorType, KeyType, VariablesType>(
|
||||
final mutation = getMutation<DataType, ErrorType, VariablesType>(
|
||||
key,
|
||||
) ??
|
||||
(mutationFn != null
|
||||
? createMutation<DataType, ErrorType, KeyType, VariablesType>(
|
||||
? createMutation<DataType, ErrorType, VariablesType>(
|
||||
key,
|
||||
mutationFn,
|
||||
retryConfig: retryConfig,
|
||||
@@ -223,12 +221,11 @@ class QueryClient {
|
||||
return result;
|
||||
}
|
||||
|
||||
Mutation<DataType, ErrorType, KeyType, VariablesType>?
|
||||
getMutation<DataType, ErrorType, KeyType, VariablesType>(
|
||||
ValueKey<KeyType> key) {
|
||||
Mutation<DataType, ErrorType, VariablesType>?
|
||||
getMutation<DataType, ErrorType, VariablesType>(String key) {
|
||||
return cache.mutations
|
||||
.firstWhereOrNull((query) => query.key == key)
|
||||
?.cast<DataType, ErrorType, KeyType, VariablesType>();
|
||||
?.cast<DataType, ErrorType, VariablesType>();
|
||||
}
|
||||
|
||||
static QueryClient of(BuildContext context) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import 'package:fl_query/src/collections/refresh_config.dart';
|
||||
import 'package:fl_query/src/collections/retry_config.dart';
|
||||
import 'package:fl_query/src/core/retryer.dart';
|
||||
import 'package:fl_query/src/core/validation.dart';
|
||||
import 'package:flutter/material.dart' hide Listener;
|
||||
import 'package:hive_flutter/adapters.dart';
|
||||
import 'package:mutex/mutex.dart';
|
||||
import 'package:state_notifier/state_notifier.dart';
|
||||
@@ -104,10 +103,10 @@ class PageEvent<T, P> {
|
||||
}
|
||||
}
|
||||
|
||||
class InfiniteQuery<DataType, ErrorType, KeyType, PageType>
|
||||
class InfiniteQuery<DataType, ErrorType, PageType>
|
||||
extends StateNotifier<InfiniteQueryState<DataType, ErrorType, PageType>>
|
||||
with Retryer<DataType, ErrorType> {
|
||||
final ValueKey<KeyType> key;
|
||||
final String key;
|
||||
final RetryConfig retryConfig;
|
||||
final RefreshConfig refreshConfig;
|
||||
final JsonConfig<DataType>? jsonConfig;
|
||||
@@ -135,7 +134,7 @@ class InfiniteQuery<DataType, ErrorType, KeyType, PageType>
|
||||
)) {
|
||||
if (jsonConfig != null) {
|
||||
_mutex.protect(() async {
|
||||
final Map? json = await _box.get(key.value);
|
||||
final Map? json = await _box.get(key);
|
||||
if (json != null) {
|
||||
state = state.copyWith(
|
||||
pages: json.entries
|
||||
@@ -223,7 +222,7 @@ class InfiniteQuery<DataType, ErrorType, KeyType, PageType>
|
||||
_dataController.add(PageEvent.fromPage(dataPage));
|
||||
if (jsonConfig != null) {
|
||||
await _box.put(
|
||||
key.value,
|
||||
key,
|
||||
Map.fromEntries(
|
||||
state.pages.map(
|
||||
(e) => MapEntry(
|
||||
@@ -359,9 +358,8 @@ class InfiniteQuery<DataType, ErrorType, KeyType, PageType>
|
||||
@override
|
||||
int get hashCode => key.hashCode;
|
||||
|
||||
InfiniteQuery<NewDataType, NewErrorType, NewKeyType, NewPageType>
|
||||
cast<NewDataType, NewErrorType, NewKeyType, NewPageType>() {
|
||||
return this
|
||||
as InfiniteQuery<NewDataType, NewErrorType, NewKeyType, NewPageType>;
|
||||
InfiniteQuery<NewDataType, NewErrorType, NewPageType>
|
||||
cast<NewDataType, NewErrorType, NewPageType>() {
|
||||
return this as InfiniteQuery<NewDataType, NewErrorType, NewPageType>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'dart:async';
|
||||
import 'package:fl_query/src/collections/default_configs.dart';
|
||||
import 'package:fl_query/src/collections/retry_config.dart';
|
||||
import 'package:fl_query/src/core/retryer.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mutex/mutex.dart';
|
||||
import 'package:state_notifier/state_notifier.dart';
|
||||
|
||||
@@ -39,10 +38,10 @@ class MutationState<DataType, ErrorType, VariablesType> {
|
||||
}
|
||||
}
|
||||
|
||||
class Mutation<DataType, ErrorType, KeyType, VariablesType>
|
||||
class Mutation<DataType, ErrorType, VariablesType>
|
||||
extends StateNotifier<MutationState<DataType, ErrorType, VariablesType>>
|
||||
with Retryer<DataType, ErrorType> {
|
||||
final ValueKey<KeyType> key;
|
||||
final String key;
|
||||
final MutationFn<DataType, VariablesType> mutationFn;
|
||||
|
||||
final RetryConfig retryConfig;
|
||||
@@ -123,16 +122,14 @@ class Mutation<DataType, ErrorType, KeyType, VariablesType>
|
||||
|
||||
@override
|
||||
operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other is Mutation && key.value == other.key.value);
|
||||
return identical(this, other) || (other is Mutation && key == other.key);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => key.hashCode;
|
||||
|
||||
Mutation<NewDataType, NewErrorType, NewKeyType, NewVariablesType>
|
||||
cast<NewDataType, NewErrorType, NewKeyType, NewVariablesType>() {
|
||||
return this
|
||||
as Mutation<NewDataType, NewErrorType, NewKeyType, NewVariablesType>;
|
||||
Mutation<NewDataType, NewErrorType, NewVariablesType>
|
||||
cast<NewDataType, NewErrorType, NewVariablesType>() {
|
||||
return this as Mutation<NewDataType, NewErrorType, NewVariablesType>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import 'package:fl_query/src/collections/refresh_config.dart';
|
||||
import 'package:fl_query/src/collections/retry_config.dart';
|
||||
import 'package:fl_query/src/core/retryer.dart';
|
||||
import 'package:fl_query/src/core/validation.dart';
|
||||
import 'package:flutter/material.dart' hide Listener;
|
||||
import 'package:hive_flutter/adapters.dart';
|
||||
import 'package:mutex/mutex.dart';
|
||||
import 'package:state_notifier/state_notifier.dart';
|
||||
@@ -45,10 +44,10 @@ class QueryState<DataType, ErrorType> with Invalidation {
|
||||
}
|
||||
}
|
||||
|
||||
class Query<DataType, ErrorType, KeyType>
|
||||
class Query<DataType, ErrorType>
|
||||
extends StateNotifier<QueryState<DataType, ErrorType>>
|
||||
with Retryer<DataType, ErrorType> {
|
||||
final ValueKey<KeyType> key;
|
||||
final String key;
|
||||
|
||||
final RefreshConfig refreshConfig;
|
||||
final RetryConfig retryConfig;
|
||||
@@ -178,15 +177,13 @@ class Query<DataType, ErrorType, KeyType>
|
||||
|
||||
@override
|
||||
operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other is Query && key.value == other.key.value);
|
||||
return identical(this, other) || (other is Query && key == other.key);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => key.hashCode;
|
||||
|
||||
Query<NewDataType, NewErrorType, NewKeyType>
|
||||
cast<NewDataType, NewErrorType, NewKeyType>() {
|
||||
return this as Query<NewDataType, NewErrorType, NewKeyType>;
|
||||
Query<NewDataType, NewErrorType> cast<NewDataType, NewErrorType>() {
|
||||
return this as Query<NewDataType, NewErrorType>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,16 +8,15 @@ import 'package:fl_query/src/core/client.dart';
|
||||
import 'package:fl_query/src/core/infinite_query.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
typedef InfiniteQueryBuilderFn<DataType, ErrorType, KeyType, PageType> = Widget
|
||||
Function(
|
||||
typedef InfiniteQueryBuilderFn<DataType, ErrorType, PageType> = Widget Function(
|
||||
BuildContext context,
|
||||
InfiniteQuery<DataType, ErrorType, KeyType, PageType> query,
|
||||
InfiniteQuery<DataType, ErrorType, PageType> query,
|
||||
);
|
||||
|
||||
class InfiniteQueryBuilder<DataType, ErrorType, KeyType, PageType>
|
||||
class InfiniteQueryBuilder<DataType, ErrorType, PageType>
|
||||
extends StatefulWidget {
|
||||
final InfiniteQueryFn<DataType, PageType> queryFn;
|
||||
final ValueKey<KeyType> queryKey;
|
||||
final String queryKey;
|
||||
|
||||
final PageType initialPage;
|
||||
final InfiniteQueryNextPage<DataType, PageType> nextPage;
|
||||
@@ -31,7 +30,7 @@ class InfiniteQueryBuilder<DataType, ErrorType, KeyType, PageType>
|
||||
|
||||
// widget specific
|
||||
final bool enabled;
|
||||
final InfiniteQueryBuilderFn<DataType, ErrorType, KeyType, PageType> builder;
|
||||
final InfiniteQueryBuilderFn<DataType, ErrorType, PageType> builder;
|
||||
|
||||
const InfiniteQueryBuilder(
|
||||
this.queryKey,
|
||||
@@ -52,15 +51,13 @@ class InfiniteQueryBuilder<DataType, ErrorType, KeyType, PageType>
|
||||
);
|
||||
|
||||
@override
|
||||
State<InfiniteQueryBuilder<DataType, ErrorType, KeyType, PageType>>
|
||||
createState() =>
|
||||
_InfiniteQueryBuilderState<DataType, ErrorType, KeyType, PageType>();
|
||||
State<InfiniteQueryBuilder<DataType, ErrorType, PageType>> createState() =>
|
||||
_InfiniteQueryBuilderState<DataType, ErrorType, PageType>();
|
||||
}
|
||||
|
||||
class _InfiniteQueryBuilderState<DataType, ErrorType, KeyType, PageType>
|
||||
extends State<
|
||||
InfiniteQueryBuilder<DataType, ErrorType, KeyType, PageType>> {
|
||||
InfiniteQuery<DataType, ErrorType, KeyType, PageType>? query;
|
||||
class _InfiniteQueryBuilderState<DataType, ErrorType, PageType>
|
||||
extends State<InfiniteQueryBuilder<DataType, ErrorType, PageType>> {
|
||||
InfiniteQuery<DataType, ErrorType, PageType>? query;
|
||||
|
||||
VoidCallback? removeListener;
|
||||
|
||||
|
||||
@@ -4,17 +4,16 @@ import 'package:fl_query/fl_query.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fl_query/src/widgets/state_notifier_listenable.dart';
|
||||
|
||||
typedef InfiniteQueryListenableBuilder<DataType, ErrorType, KeyType, PageType>
|
||||
= Widget Function(
|
||||
typedef InfiniteQueryListenableBuilder<DataType, ErrorType, PageType> = Widget
|
||||
Function(
|
||||
BuildContext context,
|
||||
InfiniteQuery<DataType, ErrorType, KeyType, PageType>? query,
|
||||
InfiniteQuery<DataType, ErrorType, PageType>? query,
|
||||
);
|
||||
|
||||
class InfiniteQueryListenable<DataType, ErrorType, KeyType, PageType>
|
||||
class InfiniteQueryListenable<DataType, ErrorType, PageType>
|
||||
extends StatefulWidget {
|
||||
final ValueKey<KeyType> queryKey;
|
||||
final InfiniteQueryListenableBuilder<DataType, ErrorType, KeyType, PageType>
|
||||
builder;
|
||||
final String queryKey;
|
||||
final InfiniteQueryListenableBuilder<DataType, ErrorType, PageType> builder;
|
||||
const InfiniteQueryListenable(
|
||||
this.queryKey, {
|
||||
required this.builder,
|
||||
@@ -22,14 +21,12 @@ class InfiniteQueryListenable<DataType, ErrorType, KeyType, PageType>
|
||||
});
|
||||
|
||||
@override
|
||||
State<InfiniteQueryListenable<DataType, ErrorType, KeyType, PageType>>
|
||||
createState() => _InfiniteQueryListenableState<DataType, ErrorType,
|
||||
KeyType, PageType>();
|
||||
State<InfiniteQueryListenable<DataType, ErrorType, PageType>> createState() =>
|
||||
_InfiniteQueryListenableState<DataType, ErrorType, PageType>();
|
||||
}
|
||||
|
||||
class _InfiniteQueryListenableState<DataType, ErrorType, KeyType, PageType>
|
||||
extends State<
|
||||
InfiniteQueryListenable<DataType, ErrorType, KeyType, PageType>> {
|
||||
class _InfiniteQueryListenableState<DataType, ErrorType, PageType>
|
||||
extends State<InfiniteQueryListenable<DataType, ErrorType, PageType>> {
|
||||
StreamSubscription<QueryCacheEvent>? _subscription;
|
||||
|
||||
@override
|
||||
@@ -60,8 +57,7 @@ class _InfiniteQueryListenableState<DataType, ErrorType, KeyType, PageType>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final query = QueryClient.of(context)
|
||||
.getInfiniteQuery<DataType, ErrorType, KeyType, PageType>(
|
||||
widget.queryKey);
|
||||
.getInfiniteQuery<DataType, ErrorType, PageType>(widget.queryKey);
|
||||
|
||||
if (query == null) {
|
||||
return widget.builder(context, null);
|
||||
@@ -70,8 +66,7 @@ class _InfiniteQueryListenableState<DataType, ErrorType, KeyType, PageType>
|
||||
InfiniteQueryState<DataType, ErrorType, PageType>>(
|
||||
notifier: query,
|
||||
builder: (context, notifier) {
|
||||
final query =
|
||||
notifier as InfiniteQuery<DataType, ErrorType, KeyType, PageType>;
|
||||
final query = notifier as InfiniteQuery<DataType, ErrorType, PageType>;
|
||||
return widget.builder(context, query);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -7,10 +7,9 @@ import 'package:fl_query/src/core/mutation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/src/foundation/diagnostics.dart';
|
||||
|
||||
typedef MutationBuilderFn<DataType, ErrorType, KeyType, VariablesType> = Widget
|
||||
Function(
|
||||
typedef MutationBuilderFn<DataType, ErrorType, VariablesType> = Widget Function(
|
||||
BuildContext context,
|
||||
Mutation<DataType, ErrorType, KeyType, VariablesType> mutation,
|
||||
Mutation<DataType, ErrorType, VariablesType> mutation,
|
||||
);
|
||||
typedef MutationOnDataFn<DataType, RecoveryType> = void Function(
|
||||
DataType data,
|
||||
@@ -25,10 +24,10 @@ typedef MutationOnMutationFn<VariablesType, RecoveryType>
|
||||
VariablesType variables,
|
||||
);
|
||||
|
||||
class MutationBuilder<DataType, ErrorType, KeyType, VariablesType, RecoveryType>
|
||||
class MutationBuilder<DataType, ErrorType, VariablesType, RecoveryType>
|
||||
extends StatefulWidget {
|
||||
final MutationFn<DataType, VariablesType> mutationFn;
|
||||
final ValueKey<KeyType> mutationKey;
|
||||
final String mutationKey;
|
||||
|
||||
final RetryConfig retryConfig;
|
||||
|
||||
@@ -37,9 +36,9 @@ class MutationBuilder<DataType, ErrorType, KeyType, VariablesType, RecoveryType>
|
||||
final MutationOnMutationFn<VariablesType, RecoveryType>? onMutate;
|
||||
|
||||
// widget specific
|
||||
final MutationBuilderFn<DataType, ErrorType, KeyType, VariablesType> builder;
|
||||
final List<ValueKey>? refreshQueries;
|
||||
final List<ValueKey>? refreshInfiniteQueries;
|
||||
final MutationBuilderFn<DataType, ErrorType, VariablesType> builder;
|
||||
final List<String>? refreshQueries;
|
||||
final List<String>? refreshInfiniteQueries;
|
||||
|
||||
const MutationBuilder(
|
||||
this.mutationKey,
|
||||
@@ -55,18 +54,15 @@ class MutationBuilder<DataType, ErrorType, KeyType, VariablesType, RecoveryType>
|
||||
});
|
||||
|
||||
@override
|
||||
State<
|
||||
MutationBuilder<DataType, ErrorType, KeyType, VariablesType,
|
||||
RecoveryType>> createState() => _MutationBuilderState<DataType,
|
||||
ErrorType, KeyType, VariablesType, RecoveryType>();
|
||||
State<MutationBuilder<DataType, ErrorType, VariablesType, RecoveryType>>
|
||||
createState() => _MutationBuilderState<DataType, ErrorType, VariablesType,
|
||||
RecoveryType>();
|
||||
}
|
||||
|
||||
class _MutationBuilderState<DataType, ErrorType, KeyType, VariablesType,
|
||||
RecoveryType>
|
||||
class _MutationBuilderState<DataType, ErrorType, VariablesType, RecoveryType>
|
||||
extends State<
|
||||
MutationBuilder<DataType, ErrorType, KeyType, VariablesType,
|
||||
RecoveryType>> {
|
||||
Mutation<DataType, ErrorType, KeyType, VariablesType>? mutation;
|
||||
MutationBuilder<DataType, ErrorType, VariablesType, RecoveryType>> {
|
||||
Mutation<DataType, ErrorType, VariablesType>? mutation;
|
||||
|
||||
VoidCallback? removeListener;
|
||||
|
||||
@@ -162,8 +158,7 @@ class _MutationBuilderState<DataType, ErrorType, KeyType, VariablesType,
|
||||
|
||||
@override
|
||||
void didUpdateWidget(
|
||||
MutationBuilder<DataType, ErrorType, KeyType, VariablesType, RecoveryType>
|
||||
oldWidget,
|
||||
MutationBuilder<DataType, ErrorType, VariablesType, RecoveryType> oldWidget,
|
||||
) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
|
||||
@@ -208,12 +203,11 @@ class _MutationBuilderState<DataType, ErrorType, KeyType, VariablesType,
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
properties.add(
|
||||
DiagnosticsProperty<
|
||||
Mutation<DataType, ErrorType, KeyType, VariablesType>>(
|
||||
DiagnosticsProperty<Mutation<DataType, ErrorType, VariablesType>>(
|
||||
'mutation', mutation),
|
||||
);
|
||||
properties.add(
|
||||
DiagnosticsProperty<ValueKey<KeyType>>('mutationKey', widget.mutationKey),
|
||||
DiagnosticsProperty<String>('mutationKey', widget.mutationKey),
|
||||
);
|
||||
properties.add(
|
||||
DiagnosticsProperty<MutationFn<DataType, VariablesType>>(
|
||||
@@ -242,7 +236,7 @@ class _MutationBuilderState<DataType, ErrorType, KeyType, VariablesType,
|
||||
);
|
||||
properties.add(
|
||||
DiagnosticsProperty<
|
||||
MutationBuilderFn<DataType, ErrorType, KeyType, VariablesType>>(
|
||||
MutationBuilderFn<DataType, ErrorType, VariablesType>>(
|
||||
'builder',
|
||||
widget.builder,
|
||||
),
|
||||
|
||||
@@ -9,14 +9,14 @@ import 'package:fl_query/src/core/query.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/src/foundation/diagnostics.dart';
|
||||
|
||||
typedef QueryBuilderFn<DataType, ErrorType, KeyType> = Widget Function(
|
||||
typedef QueryBuilderFn<DataType, ErrorType> = Widget Function(
|
||||
BuildContext context,
|
||||
Query<DataType, ErrorType, KeyType> query,
|
||||
Query<DataType, ErrorType> query,
|
||||
);
|
||||
|
||||
class QueryBuilder<DataType, ErrorType, KeyType> extends StatefulWidget {
|
||||
class QueryBuilder<DataType, ErrorType> extends StatefulWidget {
|
||||
final QueryFn<DataType> queryFn;
|
||||
final ValueKey<KeyType> queryKey;
|
||||
final String queryKey;
|
||||
|
||||
final DataType? initial;
|
||||
|
||||
@@ -29,7 +29,7 @@ class QueryBuilder<DataType, ErrorType, KeyType> extends StatefulWidget {
|
||||
|
||||
// widget specific
|
||||
final bool enabled;
|
||||
final QueryBuilderFn<DataType, ErrorType, KeyType> builder;
|
||||
final QueryBuilderFn<DataType, ErrorType> builder;
|
||||
|
||||
const QueryBuilder(
|
||||
this.queryKey,
|
||||
@@ -49,13 +49,13 @@ class QueryBuilder<DataType, ErrorType, KeyType> extends StatefulWidget {
|
||||
);
|
||||
|
||||
@override
|
||||
State<QueryBuilder<DataType, ErrorType, KeyType>> createState() =>
|
||||
_QueryBuilderState<DataType, ErrorType, KeyType>();
|
||||
State<QueryBuilder<DataType, ErrorType>> createState() =>
|
||||
_QueryBuilderState<DataType, ErrorType>();
|
||||
}
|
||||
|
||||
class _QueryBuilderState<DataType, ErrorType, KeyType>
|
||||
extends State<QueryBuilder<DataType, ErrorType, KeyType>> {
|
||||
Query<DataType, ErrorType, KeyType>? query;
|
||||
class _QueryBuilderState<DataType, ErrorType>
|
||||
extends State<QueryBuilder<DataType, ErrorType>> {
|
||||
Query<DataType, ErrorType>? query;
|
||||
|
||||
VoidCallback? removeListener;
|
||||
|
||||
@@ -107,7 +107,7 @@ class _QueryBuilderState<DataType, ErrorType, KeyType>
|
||||
|
||||
@override
|
||||
void didUpdateWidget(
|
||||
QueryBuilder<DataType, ErrorType, KeyType> oldWidget,
|
||||
QueryBuilder<DataType, ErrorType> oldWidget,
|
||||
) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
|
||||
@@ -147,13 +147,13 @@ class _QueryBuilderState<DataType, ErrorType, KeyType>
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
properties.add(
|
||||
DiagnosticsProperty<Query<DataType, ErrorType, KeyType>>('query', query),
|
||||
DiagnosticsProperty<Query<DataType, ErrorType>>('query', query),
|
||||
);
|
||||
properties.add(
|
||||
DiagnosticsProperty<ValueKey<KeyType>>('queryKey', widget.queryKey),
|
||||
DiagnosticsProperty<String>('queryKey', widget.queryKey),
|
||||
);
|
||||
properties.add(
|
||||
DiagnosticsProperty<QueryBuilderFn<DataType, ErrorType, KeyType>>(
|
||||
DiagnosticsProperty<QueryBuilderFn<DataType, ErrorType>>(
|
||||
'builder', widget.builder),
|
||||
);
|
||||
properties.add(DiagnosticsProperty<DataType>('initial', widget.initial));
|
||||
|
||||
@@ -4,14 +4,14 @@ import 'package:fl_query/fl_query.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fl_query/src/widgets/state_notifier_listenable.dart';
|
||||
|
||||
typedef QueryListenableBuilder<DataType, ErrorType, KeyType> = Widget Function(
|
||||
typedef QueryListenableBuilder<DataType, ErrorType> = Widget Function(
|
||||
BuildContext context,
|
||||
Query<DataType, ErrorType, KeyType>? query,
|
||||
Query<DataType, ErrorType>? query,
|
||||
);
|
||||
|
||||
class QueryListenable<DataType, ErrorType, KeyType> extends StatefulWidget {
|
||||
final ValueKey<KeyType> queryKey;
|
||||
final QueryListenableBuilder<DataType, ErrorType, KeyType> builder;
|
||||
class QueryListenable<DataType, ErrorType> extends StatefulWidget {
|
||||
final String queryKey;
|
||||
final QueryListenableBuilder<DataType, ErrorType> builder;
|
||||
const QueryListenable(
|
||||
this.queryKey, {
|
||||
required this.builder,
|
||||
@@ -19,12 +19,12 @@ class QueryListenable<DataType, ErrorType, KeyType> extends StatefulWidget {
|
||||
});
|
||||
|
||||
@override
|
||||
State<QueryListenable<DataType, ErrorType, KeyType>> createState() =>
|
||||
_QueryListenableState<DataType, ErrorType, KeyType>();
|
||||
State<QueryListenable<DataType, ErrorType>> createState() =>
|
||||
_QueryListenableState<DataType, ErrorType>();
|
||||
}
|
||||
|
||||
class _QueryListenableState<DataType, ErrorType, KeyType>
|
||||
extends State<QueryListenable<DataType, ErrorType, KeyType>> {
|
||||
class _QueryListenableState<DataType, ErrorType>
|
||||
extends State<QueryListenable<DataType, ErrorType>> {
|
||||
StreamSubscription<QueryCacheEvent>? _subscription;
|
||||
|
||||
@override
|
||||
@@ -53,8 +53,8 @@ class _QueryListenableState<DataType, ErrorType, KeyType>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final query = QueryClient.of(context)
|
||||
.getQuery<DataType, ErrorType, KeyType>(widget.queryKey);
|
||||
final query =
|
||||
QueryClient.of(context).getQuery<DataType, ErrorType>(widget.queryKey);
|
||||
|
||||
if (query == null) {
|
||||
return widget.builder(context, null);
|
||||
@@ -62,7 +62,7 @@ class _QueryListenableState<DataType, ErrorType, KeyType>
|
||||
return StateNotifierListenable<QueryState<DataType, ErrorType>>(
|
||||
notifier: query,
|
||||
builder: (context, notifier) {
|
||||
final query = notifier as Query<DataType, ErrorType, KeyType>;
|
||||
final query = notifier as Query<DataType, ErrorType>;
|
||||
return widget.builder(context, query);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user