Skip to content

Commit

Permalink
fix: range error for empty filtered podcast subs
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier committed Jan 21, 2025
1 parent b4d143d commit 04a160c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/podcasts/view/podcasts_collection_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<LibraryModel>();
final updatesLength =
watchPropertyValue((LibraryModel m) => m.podcastUpdatesLength);
Expand Down Expand Up @@ -107,21 +106,25 @@ class PodcastsCollectionBody extends StatelessWidget with WatchItMixin {
itemCount: itemCount,
gridDelegate: audioCardGridDelegate,
itemBuilder: (context, index) {
final MapEntry<String, List<Audio>> podcast;
final MapEntry<String, List<Audio>>? 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;
Expand Down Expand Up @@ -152,15 +155,15 @@ class PodcastsCollectionBody extends StatelessWidget with WatchItMixin {
),
onPlay: () => di<PlayerModel>()
.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),
);
},
),
Expand Down

0 comments on commit 04a160c

Please sign in to comment.