Skip to content

Commit

Permalink
Merge pull request #565 from pastordee/development
Browse files Browse the repository at this point in the history
Empty Query Widget ParseLiveList
  • Loading branch information
RodrigoSMarques authored Feb 14, 2021
2 parents 456484a + 7cc318e commit 0e604ec
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
20 changes: 17 additions & 3 deletions packages/flutter/lib/src/utils/parse_live_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ParseLiveGridWidget<T extends sdk.ParseObject> extends StatefulWidget {
Key key,
@required this.query,
this.gridLoadingElement,
this.queryEmptyElement,
this.duration = const Duration(milliseconds: 300),
this.scrollPhysics,
this.scrollController,
Expand All @@ -28,6 +29,7 @@ class ParseLiveGridWidget<T extends sdk.ParseObject> extends StatefulWidget {

final sdk.QueryBuilder<T> query;
final Widget gridLoadingElement;
final Widget queryEmptyElement;
final Duration duration;
final ScrollPhysics scrollPhysics;
final ScrollController scrollController;
Expand Down Expand Up @@ -100,6 +102,15 @@ class _ParseLiveGridWidgetState<T extends sdk.ParseObject>
lazyLoading: lazyLoading,
preloadedColumns: preloadedColumns,
).then((sdk.ParseLiveList<T> value) {
if (value.size > 0) {
setState(() {
noData = false;
});
} else {
setState(() {
noData = true;
});
}
setState(() {
_liveGrid = value;
_liveGrid.stream
Expand All @@ -117,12 +128,15 @@ class _ParseLiveGridWidgetState<T extends sdk.ParseObject>
final GlobalKey<AnimatedListState> _animatedListKey =
GlobalKey<AnimatedListState>();
final ChildBuilder<T> removedItemBuilder;
bool noData = false;

@override
Widget build(BuildContext context) {
return _liveGrid == null
? widget.gridLoadingElement ?? Container()
: buildAnimatedGrid();
: noData
? widget.queryEmptyElement ?? Container()
: buildAnimatedGrid();
}

@override
Expand All @@ -141,7 +155,7 @@ class _ParseLiveGridWidgetState<T extends sdk.ParseObject>
).animate(
CurvedAnimation(
parent: widget.animationController,
curve: Interval(
curve: const Interval(
0,
0.5,
curve: Curves.decelerate,
Expand All @@ -150,7 +164,7 @@ class _ParseLiveGridWidgetState<T extends sdk.ParseObject>
);
return GridView.builder(
itemCount: _liveGrid?.size,
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: widget.crossAxisCount,
crossAxisSpacing: widget.crossAxisSpacing,
mainAxisSpacing: widget.mainAxisSpacing,
Expand Down
25 changes: 24 additions & 1 deletion packages/flutter/lib/src/utils/parse_live_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ParseLiveListWidget<T extends sdk.ParseObject> extends StatefulWidget {
Key key,
@required this.query,
this.listLoadingElement,
this.queryEmptyElement,
this.duration = const Duration(milliseconds: 300),
this.scrollPhysics,
this.scrollController,
Expand All @@ -26,6 +27,7 @@ class ParseLiveListWidget<T extends sdk.ParseObject> extends StatefulWidget {

final sdk.QueryBuilder<T> query;
final Widget listLoadingElement;
final Widget queryEmptyElement;
final Duration duration;
final ScrollPhysics scrollPhysics;
final ScrollController scrollController;
Expand Down Expand Up @@ -91,6 +93,15 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
lazyLoading: lazyLoading,
preloadedColumns: preloadedColumns,
).then((sdk.ParseLiveList<T> value) {
if (value.size > 0) {
setState(() {
noData = false;
});
} else {
setState(() {
noData = true;
});
}
setState(() {
_liveList = value;
_liveList.stream
Expand All @@ -115,6 +126,15 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
preLoadedData: () => event.object,
),
duration: widget.duration);
if (value.size > 0) {
setState(() {
noData = false;
});
} else {
setState(() {
noData = true;
});
}
}
});
});
Expand All @@ -126,12 +146,15 @@ class _ParseLiveListWidgetState<T extends sdk.ParseObject>
final GlobalKey<AnimatedListState> _animatedListKey =
GlobalKey<AnimatedListState>();
final ChildBuilder<T> removedItemBuilder;
bool noData = false;

@override
Widget build(BuildContext context) {
return _liveList == null
? widget.listLoadingElement ?? Container()
: buildAnimatedList();
: noData
? widget.queryEmptyElement ?? Container()
: buildAnimatedList();
}

@override
Expand Down

0 comments on commit 0e604ec

Please sign in to comment.