From 5f1df5a87d8fb7980b52cf57b7b6bedea57a1269 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sat, 2 Dec 2023 22:49:29 +0600 Subject: [PATCH] fix: Playlist refresh not working #915 --- .../shared/tracks_view/track_view.dart | 23 +++++++++++-------- .../shared/tracks_view/track_view_props.dart | 9 ++++++-- lib/pages/playlist/liked_playlist.dart | 3 +++ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/lib/components/shared/tracks_view/track_view.dart b/lib/components/shared/tracks_view/track_view.dart index a65bcff14..217aaed41 100644 --- a/lib/components/shared/tracks_view/track_view.dart +++ b/lib/components/shared/tracks_view/track_view.dart @@ -28,16 +28,19 @@ class TrackView extends HookConsumerWidget { ) : null, extendBodyBehindAppBar: true, - body: CustomScrollView( - slivers: [ - const TrackViewFlexHeader(), - SliverAnimatedSwitcher( - duration: const Duration(milliseconds: 500), - child: props.tracks.isEmpty - ? const ShimmerTrackTileGroup() - : const TrackViewBodySection(), - ), - ], + body: RefreshIndicator( + onRefresh: props.pagination.onRefresh, + child: CustomScrollView( + slivers: [ + const TrackViewFlexHeader(), + SliverAnimatedSwitcher( + duration: const Duration(milliseconds: 500), + child: props.tracks.isEmpty + ? const ShimmerTrackTileGroup() + : const TrackViewBodySection(), + ), + ], + ), ), ); } diff --git a/lib/components/shared/tracks_view/track_view_props.dart b/lib/components/shared/tracks_view/track_view_props.dart index 59c05db29..1c6c76473 100644 --- a/lib/components/shared/tracks_view/track_view_props.dart +++ b/lib/components/shared/tracks_view/track_view_props.dart @@ -6,6 +6,7 @@ class PaginationProps { final bool hasNextPage; final bool isLoading; final VoidCallback onFetchMore; + final Future Function() onRefresh; final Future> Function() onFetchAll; const PaginationProps({ @@ -13,6 +14,7 @@ class PaginationProps { required this.isLoading, required this.onFetchMore, required this.onFetchAll, + required this.onRefresh, }); factory PaginationProps.fromQuery( @@ -24,6 +26,7 @@ class PaginationProps { isLoading: query.isLoadingNextPage, onFetchMore: query.fetchNext, onFetchAll: onFetchAll, + onRefresh: query.refreshAll, ); } @@ -33,7 +36,8 @@ class PaginationProps { other.hasNextPage == hasNextPage && other.isLoading == isLoading && other.onFetchMore == onFetchMore && - other.onFetchAll == onFetchAll; + other.onFetchAll == onFetchAll && + other.onRefresh == onRefresh; } @override @@ -42,7 +46,8 @@ class PaginationProps { hasNextPage.hashCode ^ isLoading.hashCode ^ onFetchMore.hashCode ^ - onFetchAll.hashCode; + onFetchAll.hashCode ^ + onRefresh.hashCode; } class InheritedTrackView extends InheritedWidget { diff --git a/lib/pages/playlist/liked_playlist.dart b/lib/pages/playlist/liked_playlist.dart index 1f252ed4c..5972a3034 100644 --- a/lib/pages/playlist/liked_playlist.dart +++ b/lib/pages/playlist/liked_playlist.dart @@ -31,6 +31,9 @@ class LikedPlaylistPage extends HookConsumerWidget { onFetchAll: () async { return tracks.toList(); }, + onRefresh: () async { + await likedTracks.refresh(); + }, ), title: playlist.name!, description: playlist.description,