Docs: Front page Images added

QueryBuilder & useQuery onData, onError not working bugfix
This commit is contained in:
Kingkor Roy Tirtho
2022-07-03 19:08:18 +06:00
parent 8a4f1f7545
commit 53fc86eac1
13 changed files with 274 additions and 42 deletions
@@ -62,6 +62,8 @@ Query<T, Outside> useQuery<T extends Object, Outside>({
}, []);
useEffect(() {
final hasOnErrorChanged = oldOnError != onError && oldOnError != null;
final hasOnDataChanged = oldOnData != onData && oldOnData != null;
if (oldJob != null && oldJob.queryKey != job.queryKey) {
disposeQuery();
query.value = Query.fromOptions(
@@ -80,12 +82,14 @@ Query<T, Outside> useQuery<T extends Object, Outside>({
onError: onError,
key: uKey,
);
if (hasOnDataChanged) query.value.onDataListeners.remove(oldOnData);
if (hasOnErrorChanged) query.value.onErrorListeners.remove(oldOnError);
} else {
if (oldOnData != onData && oldOnData != null) {
if (hasOnDataChanged) {
query.value.onDataListeners.remove(oldOnData);
if (onData != null) query.value.onDataListeners.add(onData);
}
if (oldOnError != onError && oldOnError != null) {
if (hasOnErrorChanged) {
query.value.onErrorListeners.remove(oldOnError);
if (onError != null) query.value.onErrorListeners.add(onError);
}
+9 -2
View File
@@ -65,6 +65,11 @@ class _QueryBuilderState<T extends Object, Outside>
@override
void didUpdateWidget(covariant oldWidget) {
final hasOnErrorChanged =
oldWidget.onError != widget.onError && oldWidget.onError != null;
final hasOnDataChanged =
oldWidget.onData != widget.onData && oldWidget.onData != null;
// re-init the query-builder when new queryJob is appended
if (oldWidget.job.queryKey != widget.job.queryKey) {
_queryDispose();
@@ -79,12 +84,14 @@ class _QueryBuilderState<T extends Object, Outside>
onError: widget.onError,
key: uKey,
);
if (hasOnDataChanged) query?.onDataListeners.remove(oldWidget.onData);
if (hasOnErrorChanged) query?.onErrorListeners.remove(oldWidget.onError);
} else {
if (oldWidget.onData != widget.onData && oldWidget.onData != null) {
if (hasOnDataChanged) {
query?.onDataListeners.remove(oldWidget.onData);
if (widget.onData != null) query?.onDataListeners.add(widget.onData!);
}
if (oldWidget.onError != widget.onError && oldWidget.onError != null) {
if (hasOnErrorChanged) {
query?.onErrorListeners.remove(oldWidget.onError);
if (widget.onError != null)
query?.onErrorListeners.add(widget.onError!);