From 04a160cd2ab2e1c88f1d6c3e297437003d995f0a Mon Sep 17 00:00:00 2001 From: Feichtmeier Date: Tue, 21 Jan 2025 14:05:34 +0100 Subject: [PATCH] fix: range error for empty filtered podcast subs --- lib/podcasts/view/podcasts_collection_body.dart | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/podcasts/view/podcasts_collection_body.dart b/lib/podcasts/view/podcasts_collection_body.dart index 10e73a866..b38a1dd5b 100644 --- a/lib/podcasts/view/podcasts_collection_body.dart +++ b/lib/podcasts/view/podcasts_collection_body.dart @@ -37,7 +37,6 @@ class PodcastsCollectionBody extends StatelessWidget with WatchItMixin { final loading = watchPropertyValue((PodcastModel m) => m.checkingForUpdates); final subs = watchPropertyValue((LibraryModel m) => m.podcasts); - watchPropertyValue((LibraryModel m) => m.podcastUpdatesLength); final libraryModel = di(); final updatesLength = watchPropertyValue((LibraryModel m) => m.podcastUpdatesLength); @@ -107,21 +106,25 @@ class PodcastsCollectionBody extends StatelessWidget with WatchItMixin { itemCount: itemCount, gridDelegate: audioCardGridDelegate, itemBuilder: (context, index) { - final MapEntry> podcast; + final MapEntry>? podcast; if (updatesOnly) { podcast = subs.entries .where( (e) => libraryModel.podcastUpdateAvailable(e.key), ) - .elementAt(index); + .elementAtOrNull(index); } else if (downloadsOnly) { podcast = subs.entries .where((e) => libraryModel.feedHasDownload(e.key)) - .elementAt(index); + .elementAtOrNull(index); } else { podcast = subs.entries.elementAt(index); } + if (podcast == null) { + return const SizedBox.shrink(); + } + final artworkUrl600 = podcast.value.firstOrNull?.albumArtUrl ?? podcast.value.firstOrNull?.imageUrl; @@ -152,15 +155,15 @@ class PodcastsCollectionBody extends StatelessWidget with WatchItMixin { ), onPlay: () => di() .startPlaylist( - audios: podcast.value, + audios: podcast!.value, listName: podcast.key, ) .then( (_) => libraryModel.removePodcastUpdate( - podcast.key, + podcast!.key, ), ), - onTap: () => libraryModel.push(pageId: podcast.key), + onTap: () => libraryModel.push(pageId: podcast!.key), ); }, ),