Skip to content

Commit ab9a1bc

Browse files
authored
fix livequery (#608)
Fix: ParseLiveQueryWidget wont add element to an empty list
1 parent acf1224 commit ab9a1bc

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

packages/flutter/lib/src/utils/parse_live_list.dart

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,20 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
9292
listeningIncludes: listeningIncludes,
9393
lazyLoading: lazyLoading,
9494
preloadedColumns: preloadedColumns,
95-
).then((sdk.ParseLiveList<T> value) {
96-
if (value.size > 0) {
97-
setState(() {
98-
noData = false;
99-
});
100-
} else {
101-
setState(() {
102-
noData = true;
103-
});
104-
}
95+
).then((sdk.ParseLiveList<T> livelist) {
10596
setState(() {
106-
_liveList = value;
97+
_noData = livelist.size == 0;
98+
_liveList = livelist;
10799
_liveList!.stream
108100
.listen((sdk.ParseLiveListEvent<sdk.ParseObject> event) {
109101
if (event is sdk.ParseLiveListAddEvent) {
110-
if (_animatedListKey.currentState != null)
102+
if (_animatedListKey.currentState != null) {
111103
_animatedListKey.currentState!
112104
.insertItem(event.index, duration: widget.duration);
105+
}
106+
setState(() {
107+
_noData = livelist.size == 0;
108+
});
113109
} else if (event is sdk.ParseLiveListDeleteEvent) {
114110
_animatedListKey.currentState!.removeItem(
115111
event.index,
@@ -126,15 +122,9 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
126122
preLoadedData: () => event.object as T,
127123
),
128124
duration: widget.duration);
129-
if (value.size > 0) {
130-
setState(() {
131-
noData = false;
132-
});
133-
} else {
134-
setState(() {
135-
noData = true;
136-
});
137-
}
125+
setState(() {
126+
_noData = livelist.size == 0;
127+
});
138128
}
139129
});
140130
});
@@ -146,17 +136,26 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
146136
final GlobalKey<AnimatedListState> _animatedListKey =
147137
GlobalKey<AnimatedListState>();
148138
final ChildBuilder<T>? removedItemBuilder;
149-
bool noData = true;
139+
bool _noData = true;
150140

151141
@override
152142
Widget build(BuildContext context) {
153143
if (_liveList == null) {
154144
return widget.listLoadingElement ?? Container();
145+
} else {
146+
return Stack(
147+
children: <Widget>[
148+
if (widget.queryEmptyElement != null)
149+
AnimatedOpacity(
150+
opacity: _noData ? 1 : 0,
151+
duration: widget.duration,
152+
child: widget.queryEmptyElement,
153+
),
154+
//_liveList isn't (checked above)
155+
buildAnimatedList(_liveList!),
156+
],
157+
);
155158
}
156-
if (noData) {
157-
return widget.queryEmptyElement ?? Container();
158-
}
159-
return buildAnimatedList(_liveList!);
160159
}
161160

162161
@override

0 commit comments

Comments
 (0)