feat: add support for keepPreviousData & examples regarding this
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// ignore_for_file: invalid_use_of_protected_member
|
||||
|
||||
import 'package:fl_query/src/models/query_job.dart';
|
||||
import 'package:fl_query/src/query.dart';
|
||||
import 'package:fl_query/src/query_bowl.dart';
|
||||
@@ -43,11 +45,12 @@ class _QueryBuilderState<T extends Object, Outside>
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => init());
|
||||
}
|
||||
|
||||
void init([QueryBowl? bowl]) async {
|
||||
bowl ??= QueryBowl.of(context);
|
||||
void init([T? previousData]) async {
|
||||
final bowl = QueryBowl.of(context);
|
||||
query = bowl.addQuery<T, Outside>(
|
||||
widget.job,
|
||||
externalData: widget.externalData,
|
||||
previousData: previousData,
|
||||
key: uKey,
|
||||
onData: widget.onData,
|
||||
onError: widget.onError,
|
||||
@@ -72,7 +75,17 @@ class _QueryBuilderState<T extends Object, Outside>
|
||||
// re-init the query-builder when new queryJob is appended
|
||||
if (oldWidget.job.queryKey != widget.job.queryKey) {
|
||||
_queryDispose();
|
||||
init();
|
||||
|
||||
/// setting the new query's initial data as prev query's data
|
||||
/// when [job.keepPreviousData] is true and both are dynamic
|
||||
if (oldWidget.job.isDynamic &&
|
||||
widget.job.isDynamic &&
|
||||
oldWidget.job.keepPreviousData == true &&
|
||||
widget.job.keepPreviousData == true) {
|
||||
init(query?.data);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
} else if (oldWidget.externalData != null &&
|
||||
widget.externalData != null &&
|
||||
!isShallowEqual(oldWidget.externalData!, widget.externalData!)) {
|
||||
|
||||
Reference in New Issue
Block a user