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