Skip to content

Commit 5fb9716

Browse files
committed
update
1 parent 456484a commit 5fb9716

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

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

Lines changed: 19 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,17 @@ class _ParseLiveGridWidgetState<T extends sdk.ParseObject>
100102
lazyLoading: lazyLoading,
101103
preloadedColumns: preloadedColumns,
102104
).then((sdk.ParseLiveList<T> value) {
105+
query.count().then((value) {
106+
if (value.count > 0) {
107+
setState(() {
108+
noData = false;
109+
});
110+
} else {
111+
setState(() {
112+
noData = true;
113+
});
114+
}
115+
});
103116
setState(() {
104117
_liveGrid = value;
105118
_liveGrid.stream
@@ -117,12 +130,15 @@ class _ParseLiveGridWidgetState<T extends sdk.ParseObject>
117130
final GlobalKey<AnimatedListState> _animatedListKey =
118131
GlobalKey<AnimatedListState>();
119132
final ChildBuilder<T> removedItemBuilder;
133+
bool noData = false;
120134

121135
@override
122136
Widget build(BuildContext context) {
123137
return _liveGrid == null
124138
? widget.gridLoadingElement ?? Container()
125-
: buildAnimatedGrid();
139+
: noData
140+
? widget.queryEmptyElement ?? Container()
141+
: buildAnimatedGrid();
126142
}
127143

128144
@override
@@ -141,7 +157,7 @@ class _ParseLiveGridWidgetState<T extends sdk.ParseObject>
141157
).animate(
142158
CurvedAnimation(
143159
parent: widget.animationController,
144-
curve: Interval(
160+
curve: const Interval(
145161
0,
146162
0.5,
147163
curve: Curves.decelerate,
@@ -150,7 +166,7 @@ class _ParseLiveGridWidgetState<T extends sdk.ParseObject>
150166
);
151167
return GridView.builder(
152168
itemCount: _liveGrid?.size,
153-
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
169+
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
154170
crossAxisCount: widget.crossAxisCount,
155171
crossAxisSpacing: widget.crossAxisSpacing,
156172
mainAxisSpacing: widget.mainAxisSpacing,

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

Lines changed: 31 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,17 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
9193
lazyLoading: lazyLoading,
9294
preloadedColumns: preloadedColumns,
9395
).then((sdk.ParseLiveList<T> value) {
96+
query.count().then((value) {
97+
if (value.count > 0) {
98+
setState(() {
99+
noData = false;
100+
});
101+
} else {
102+
setState(() {
103+
noData = true;
104+
});
105+
}
106+
});
94107
setState(() {
95108
_liveList = value;
96109
_liveList.stream
@@ -99,6 +112,9 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
99112
if (_animatedListKey.currentState != null)
100113
_animatedListKey.currentState
101114
.insertItem(event.index, duration: widget.duration);
115+
setState(() {
116+
noData = false;
117+
});
102118
} else if (event is sdk.ParseLiveListDeleteEvent) {
103119
_animatedListKey.currentState.removeItem(
104120
event.index,
@@ -115,6 +131,17 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
115131
preLoadedData: () => event.object,
116132
),
117133
duration: widget.duration);
134+
query.count().then((value) {
135+
if (value.count > 0) {
136+
setState(() {
137+
noData = false;
138+
});
139+
} else {
140+
setState(() {
141+
noData = true;
142+
});
143+
}
144+
});
118145
}
119146
});
120147
});
@@ -126,12 +153,15 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
126153
final GlobalKey<AnimatedListState> _animatedListKey =
127154
GlobalKey<AnimatedListState>();
128155
final ChildBuilder<T> removedItemBuilder;
156+
bool noData = false;
129157

130158
@override
131159
Widget build(BuildContext context) {
132160
return _liveList == null
133161
? widget.listLoadingElement ?? Container()
134-
: buildAnimatedList();
162+
: noData
163+
? widget.queryEmptyElement ?? Container()
164+
: buildAnimatedList();
135165
}
136166

137167
@override

0 commit comments

Comments
 (0)