From 5fb97160d789baae7891aed59222643f844747be Mon Sep 17 00:00:00 2001 From: pastordee Date: Sat, 13 Feb 2021 19:45:52 +0000 Subject: [PATCH 1/3] update --- .../lib/src/utils/parse_live_grid.dart | 22 +++++++++++-- .../lib/src/utils/parse_live_list.dart | 32 ++++++++++++++++++- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/packages/flutter/lib/src/utils/parse_live_grid.dart b/packages/flutter/lib/src/utils/parse_live_grid.dart index 3060dbd64..bb6b91de9 100644 --- a/packages/flutter/lib/src/utils/parse_live_grid.dart +++ b/packages/flutter/lib/src/utils/parse_live_grid.dart @@ -5,6 +5,7 @@ class ParseLiveGridWidget extends StatefulWidget { Key key, @required this.query, this.gridLoadingElement, + this.queryEmptyElement, this.duration = const Duration(milliseconds: 300), this.scrollPhysics, this.scrollController, @@ -28,6 +29,7 @@ class ParseLiveGridWidget extends StatefulWidget { final sdk.QueryBuilder query; final Widget gridLoadingElement; + final Widget queryEmptyElement; final Duration duration; final ScrollPhysics scrollPhysics; final ScrollController scrollController; @@ -100,6 +102,17 @@ class _ParseLiveGridWidgetState lazyLoading: lazyLoading, preloadedColumns: preloadedColumns, ).then((sdk.ParseLiveList value) { + query.count().then((value) { + if (value.count > 0) { + setState(() { + noData = false; + }); + } else { + setState(() { + noData = true; + }); + } + }); setState(() { _liveGrid = value; _liveGrid.stream @@ -117,12 +130,15 @@ class _ParseLiveGridWidgetState final GlobalKey _animatedListKey = GlobalKey(); final ChildBuilder removedItemBuilder; + bool noData = false; @override Widget build(BuildContext context) { return _liveGrid == null ? widget.gridLoadingElement ?? Container() - : buildAnimatedGrid(); + : noData + ? widget.queryEmptyElement ?? Container() + : buildAnimatedGrid(); } @override @@ -141,7 +157,7 @@ class _ParseLiveGridWidgetState ).animate( CurvedAnimation( parent: widget.animationController, - curve: Interval( + curve: const Interval( 0, 0.5, curve: Curves.decelerate, @@ -150,7 +166,7 @@ class _ParseLiveGridWidgetState ); return GridView.builder( itemCount: _liveGrid?.size, - gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount( + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: widget.crossAxisCount, crossAxisSpacing: widget.crossAxisSpacing, mainAxisSpacing: widget.mainAxisSpacing, diff --git a/packages/flutter/lib/src/utils/parse_live_list.dart b/packages/flutter/lib/src/utils/parse_live_list.dart index 0fca66328..24451cab1 100644 --- a/packages/flutter/lib/src/utils/parse_live_list.dart +++ b/packages/flutter/lib/src/utils/parse_live_list.dart @@ -8,6 +8,7 @@ class ParseLiveListWidget extends StatefulWidget { Key key, @required this.query, this.listLoadingElement, + this.queryEmptyElement, this.duration = const Duration(milliseconds: 300), this.scrollPhysics, this.scrollController, @@ -26,6 +27,7 @@ class ParseLiveListWidget extends StatefulWidget { final sdk.QueryBuilder query; final Widget listLoadingElement; + final Widget queryEmptyElement; final Duration duration; final ScrollPhysics scrollPhysics; final ScrollController scrollController; @@ -91,6 +93,17 @@ class _ParseLiveListWidgetState lazyLoading: lazyLoading, preloadedColumns: preloadedColumns, ).then((sdk.ParseLiveList value) { + query.count().then((value) { + if (value.count > 0) { + setState(() { + noData = false; + }); + } else { + setState(() { + noData = true; + }); + } + }); setState(() { _liveList = value; _liveList.stream @@ -99,6 +112,9 @@ class _ParseLiveListWidgetState if (_animatedListKey.currentState != null) _animatedListKey.currentState .insertItem(event.index, duration: widget.duration); + setState(() { + noData = false; + }); } else if (event is sdk.ParseLiveListDeleteEvent) { _animatedListKey.currentState.removeItem( event.index, @@ -115,6 +131,17 @@ class _ParseLiveListWidgetState preLoadedData: () => event.object, ), duration: widget.duration); + query.count().then((value) { + if (value.count > 0) { + setState(() { + noData = false; + }); + } else { + setState(() { + noData = true; + }); + } + }); } }); }); @@ -126,12 +153,15 @@ class _ParseLiveListWidgetState final GlobalKey _animatedListKey = GlobalKey(); final ChildBuilder removedItemBuilder; + bool noData = false; @override Widget build(BuildContext context) { return _liveList == null ? widget.listLoadingElement ?? Container() - : buildAnimatedList(); + : noData + ? widget.queryEmptyElement ?? Container() + : buildAnimatedList(); } @override From d41afcd60e5cab84e78af999810a04c4ab31dce1 Mon Sep 17 00:00:00 2001 From: pastordee Date: Sat, 13 Feb 2021 21:22:22 +0000 Subject: [PATCH 2/3] Empty Query Widget ParseLiveList --- .../lib/src/utils/parse_live_grid.dart | 20 +++++------ .../lib/src/utils/parse_live_list.dart | 34 +++++-------------- 2 files changed, 18 insertions(+), 36 deletions(-) diff --git a/packages/flutter/lib/src/utils/parse_live_grid.dart b/packages/flutter/lib/src/utils/parse_live_grid.dart index bb6b91de9..53546fade 100644 --- a/packages/flutter/lib/src/utils/parse_live_grid.dart +++ b/packages/flutter/lib/src/utils/parse_live_grid.dart @@ -102,17 +102,6 @@ class _ParseLiveGridWidgetState lazyLoading: lazyLoading, preloadedColumns: preloadedColumns, ).then((sdk.ParseLiveList value) { - query.count().then((value) { - if (value.count > 0) { - setState(() { - noData = false; - }); - } else { - setState(() { - noData = true; - }); - } - }); setState(() { _liveGrid = value; _liveGrid.stream @@ -122,6 +111,15 @@ class _ParseLiveGridWidgetState } }); }); + if (value.size > 0) { + setState(() { + noData = false; + }); + } else { + setState(() { + noData = true; + }); + } }); } diff --git a/packages/flutter/lib/src/utils/parse_live_list.dart b/packages/flutter/lib/src/utils/parse_live_list.dart index 24451cab1..0911c6beb 100644 --- a/packages/flutter/lib/src/utils/parse_live_list.dart +++ b/packages/flutter/lib/src/utils/parse_live_list.dart @@ -93,17 +93,6 @@ class _ParseLiveListWidgetState lazyLoading: lazyLoading, preloadedColumns: preloadedColumns, ).then((sdk.ParseLiveList value) { - query.count().then((value) { - if (value.count > 0) { - setState(() { - noData = false; - }); - } else { - setState(() { - noData = true; - }); - } - }); setState(() { _liveList = value; _liveList.stream @@ -112,9 +101,6 @@ class _ParseLiveListWidgetState if (_animatedListKey.currentState != null) _animatedListKey.currentState .insertItem(event.index, duration: widget.duration); - setState(() { - noData = false; - }); } else if (event is sdk.ParseLiveListDeleteEvent) { _animatedListKey.currentState.removeItem( event.index, @@ -131,20 +117,18 @@ class _ParseLiveListWidgetState preLoadedData: () => event.object, ), duration: widget.duration); - query.count().then((value) { - if (value.count > 0) { - setState(() { - noData = false; - }); - } else { - setState(() { - noData = true; - }); - } - }); } }); }); + if (value.size > 0) { + setState(() { + noData = false; + }); + } else { + setState(() { + noData = true; + }); + } }); } From 7cc318e0203e4d75e06af56172f758825bd70cf7 Mon Sep 17 00:00:00 2001 From: pastordee Date: Sat, 13 Feb 2021 21:54:49 +0000 Subject: [PATCH 3/3] Empty Query Widget ParseLiveList --- .../lib/src/utils/parse_live_grid.dart | 18 ++++++------- .../lib/src/utils/parse_live_list.dart | 27 ++++++++++++------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/packages/flutter/lib/src/utils/parse_live_grid.dart b/packages/flutter/lib/src/utils/parse_live_grid.dart index 53546fade..75f970adb 100644 --- a/packages/flutter/lib/src/utils/parse_live_grid.dart +++ b/packages/flutter/lib/src/utils/parse_live_grid.dart @@ -102,15 +102,6 @@ class _ParseLiveGridWidgetState lazyLoading: lazyLoading, preloadedColumns: preloadedColumns, ).then((sdk.ParseLiveList value) { - setState(() { - _liveGrid = value; - _liveGrid.stream - .listen((sdk.ParseLiveListEvent event) { - if (mounted) { - setState(() {}); - } - }); - }); if (value.size > 0) { setState(() { noData = false; @@ -120,6 +111,15 @@ class _ParseLiveGridWidgetState noData = true; }); } + setState(() { + _liveGrid = value; + _liveGrid.stream + .listen((sdk.ParseLiveListEvent event) { + if (mounted) { + setState(() {}); + } + }); + }); }); } diff --git a/packages/flutter/lib/src/utils/parse_live_list.dart b/packages/flutter/lib/src/utils/parse_live_list.dart index 0911c6beb..cd9fbfdc2 100644 --- a/packages/flutter/lib/src/utils/parse_live_list.dart +++ b/packages/flutter/lib/src/utils/parse_live_list.dart @@ -93,6 +93,15 @@ class _ParseLiveListWidgetState lazyLoading: lazyLoading, preloadedColumns: preloadedColumns, ).then((sdk.ParseLiveList value) { + if (value.size > 0) { + setState(() { + noData = false; + }); + } else { + setState(() { + noData = true; + }); + } setState(() { _liveList = value; _liveList.stream @@ -117,18 +126,18 @@ class _ParseLiveListWidgetState preLoadedData: () => event.object, ), duration: widget.duration); + if (value.size > 0) { + setState(() { + noData = false; + }); + } else { + setState(() { + noData = true; + }); + } } }); }); - if (value.size > 0) { - setState(() { - noData = false; - }); - } else { - setState(() { - noData = true; - }); - } }); }