Skip to content

Commit 0e604ec

Browse files
Merge pull request #565 from pastordee/development
Empty Query Widget ParseLiveList
2 parents 456484a + 7cc318e commit 0e604ec

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class ParseLiveGridWidget<T extends sdk.ParseObject> extends StatefulWidget {
55
Key key,
66
@required this.query,
77
this.gridLoadingElement,
8+
this.queryEmptyElement,
89
this.duration = const Duration(milliseconds: 300),
910
this.scrollPhysics,
1011
this.scrollController,
@@ -28,6 +29,7 @@ class ParseLiveGridWidget<T extends sdk.ParseObject> extends StatefulWidget {
2829

2930
final sdk.QueryBuilder<T> query;
3031
final Widget gridLoadingElement;
32+
final Widget queryEmptyElement;
3133
final Duration duration;
3234
final ScrollPhysics scrollPhysics;
3335
final ScrollController scrollController;
@@ -100,6 +102,15 @@ class _ParseLiveGridWidgetState<T extends sdk.ParseObject>
100102
lazyLoading: lazyLoading,
101103
preloadedColumns: preloadedColumns,
102104
).then((sdk.ParseLiveList<T> value) {
105+
if (value.size > 0) {
106+
setState(() {
107+
noData = false;
108+
});
109+
} else {
110+
setState(() {
111+
noData = true;
112+
});
113+
}
103114
setState(() {
104115
_liveGrid = value;
105116
_liveGrid.stream
@@ -117,12 +128,15 @@ class _ParseLiveGridWidgetState<T extends sdk.ParseObject>
117128
final GlobalKey<AnimatedListState> _animatedListKey =
118129
GlobalKey<AnimatedListState>();
119130
final ChildBuilder<T> removedItemBuilder;
131+
bool noData = false;
120132

121133
@override
122134
Widget build(BuildContext context) {
123135
return _liveGrid == null
124136
? widget.gridLoadingElement ?? Container()
125-
: buildAnimatedGrid();
137+
: noData
138+
? widget.queryEmptyElement ?? Container()
139+
: buildAnimatedGrid();
126140
}
127141

128142
@override
@@ -141,7 +155,7 @@ class _ParseLiveGridWidgetState<T extends sdk.ParseObject>
141155
).animate(
142156
CurvedAnimation(
143157
parent: widget.animationController,
144-
curve: Interval(
158+
curve: const Interval(
145159
0,
146160
0.5,
147161
curve: Curves.decelerate,
@@ -150,7 +164,7 @@ class _ParseLiveGridWidgetState<T extends sdk.ParseObject>
150164
);
151165
return GridView.builder(
152166
itemCount: _liveGrid?.size,
153-
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
167+
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
154168
crossAxisCount: widget.crossAxisCount,
155169
crossAxisSpacing: widget.crossAxisSpacing,
156170
mainAxisSpacing: widget.mainAxisSpacing,

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class ParseLiveListWidget<T extends sdk.ParseObject> extends StatefulWidget {
88
Key key,
99
@required this.query,
1010
this.listLoadingElement,
11+
this.queryEmptyElement,
1112
this.duration = const Duration(milliseconds: 300),
1213
this.scrollPhysics,
1314
this.scrollController,
@@ -26,6 +27,7 @@ class ParseLiveListWidget<T extends sdk.ParseObject> extends StatefulWidget {
2627

2728
final sdk.QueryBuilder<T> query;
2829
final Widget listLoadingElement;
30+
final Widget queryEmptyElement;
2931
final Duration duration;
3032
final ScrollPhysics scrollPhysics;
3133
final ScrollController scrollController;
@@ -91,6 +93,15 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
9193
lazyLoading: lazyLoading,
9294
preloadedColumns: preloadedColumns,
9395
).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+
}
94105
setState(() {
95106
_liveList = value;
96107
_liveList.stream
@@ -115,6 +126,15 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
115126
preLoadedData: () => event.object,
116127
),
117128
duration: widget.duration);
129+
if (value.size > 0) {
130+
setState(() {
131+
noData = false;
132+
});
133+
} else {
134+
setState(() {
135+
noData = true;
136+
});
137+
}
118138
}
119139
});
120140
});
@@ -126,12 +146,15 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
126146
final GlobalKey<AnimatedListState> _animatedListKey =
127147
GlobalKey<AnimatedListState>();
128148
final ChildBuilder<T> removedItemBuilder;
149+
bool noData = false;
129150

130151
@override
131152
Widget build(BuildContext context) {
132153
return _liveList == null
133154
? widget.listLoadingElement ?? Container()
134-
: buildAnimatedList();
155+
: noData
156+
? widget.queryEmptyElement ?? Container()
157+
: buildAnimatedList();
135158
}
136159

137160
@override

0 commit comments

Comments
 (0)