From b0d0f43ec078f4123c807828de2f09d1b93ff98b Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Tue, 28 Jun 2022 07:39:10 -0400 Subject: [PATCH] Reduced amount of fetches for lists (#90) --- lib/screens/home/top/categories.dart | 2 +- lib/screens/home/top/category_streams.dart | 54 ++++++++++++---------- lib/screens/home/widgets/streams_list.dart | 4 +- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/lib/screens/home/top/categories.dart b/lib/screens/home/top/categories.dart index 5b663da0..71a903b1 100644 --- a/lib/screens/home/top/categories.dart +++ b/lib/screens/home/top/categories.dart @@ -57,7 +57,7 @@ class _CategoriesState extends State with AutomaticKeepAliveClientMi ), itemCount: _categoriesStore.categories.length, itemBuilder: (context, index) { - if (index > _categoriesStore.categories.length / 2 && _categoriesStore.hasMore) { + if (index > _categoriesStore.categories.length - 8 && _categoriesStore.hasMore) { _categoriesStore.getCategories(); } return CategoryCard( diff --git a/lib/screens/home/top/category_streams.dart b/lib/screens/home/top/category_streams.dart index e33cf9b2..2d75f478 100644 --- a/lib/screens/home/top/category_streams.dart +++ b/lib/screens/home/top/category_streams.dart @@ -55,9 +55,6 @@ class _CategoryStreamsState extends State { }, child: Observer( builder: (context) { - if (widget.listStore.streams.isEmpty && widget.listStore.isLoading && widget.listStore.error == null) { - return const LoadingIndicator(subtitle: Text('Loading streams...')); - } return Stack( alignment: AlignmentDirectional.bottomCenter, children: [ @@ -104,29 +101,38 @@ class _CategoryStreamsState extends State { ), ), ), - SliverSafeArea( - top: false, - sliver: SliverList( - delegate: SliverChildBuilderDelegate( - (context, index) { - if (index > widget.listStore.streams.length / 2 && widget.listStore.hasMore) { - widget.listStore.getStreams(); - } - return Observer( - builder: (context) => StreamCard( - listStore: widget.listStore, - streamInfo: widget.listStore.streams[index], - showUptime: context.read().showThumbnailUptime, - showThumbnail: context.read().showThumbnails, - large: context.read().largeStreamCard, - showCategory: false, - ), - ); - }, - childCount: widget.listStore.streams.length, + if (widget.listStore.streams.isEmpty && widget.listStore.isLoading && widget.listStore.error == null) + const SliverFillRemaining( + child: Center( + child: LoadingIndicator( + subtitle: Text('Loading streams...'), + ), + ), + ) + else + SliverSafeArea( + top: false, + sliver: SliverList( + delegate: SliverChildBuilderDelegate( + (context, index) { + if (index > widget.listStore.streams.length - 8 && widget.listStore.hasMore) { + widget.listStore.getStreams(); + } + return Observer( + builder: (context) => StreamCard( + listStore: widget.listStore, + streamInfo: widget.listStore.streams[index], + showUptime: context.read().showThumbnailUptime, + showThumbnail: context.read().showThumbnails, + large: context.read().largeStreamCard, + showCategory: false, + ), + ); + }, + childCount: widget.listStore.streams.length, + ), ), ), - ), ], ), SafeArea( diff --git a/lib/screens/home/widgets/streams_list.dart b/lib/screens/home/widgets/streams_list.dart index 92c2e199..8d59de38 100644 --- a/lib/screens/home/widgets/streams_list.dart +++ b/lib/screens/home/widgets/streams_list.dart @@ -70,7 +70,9 @@ class _StreamsListState extends State with AutomaticKeepAliveClient controller: _listStore.scrollController, itemCount: _listStore.streams.length, itemBuilder: (context, index) { - if (index > _listStore.streams.length / 2 && _listStore.hasMore) { + if (index > _listStore.streams.length - 8 && _listStore.hasMore) { + debugPrint('$index ${_listStore.streams.length}'); + _listStore.getStreams(); } return Observer(