Skip to content

Commit 8c79169

Browse files
committed
fix: ensure playlist and song IDs are non-null before processing like status and renaming
1 parent 0a3cc86 commit 8c79169

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

lib/screens/playlist_page.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class _PlaylistPageState extends State<PlaylistPage> {
7272
_originalPlaylistList; // Keep original order separately
7373

7474
late final playlistLikeStatus = ValueNotifier<bool>(
75-
isPlaylistAlreadyLiked(widget.playlistId),
75+
widget.playlistId != null && isPlaylistAlreadyLiked(widget.playlistId!),
7676
);
7777
bool playlistOfflineStatus = false;
7878

@@ -104,6 +104,7 @@ class _PlaylistPageState extends State<PlaylistPage> {
104104

105105
@override
106106
void dispose() {
107+
playlistLikeStatus.dispose();
107108
super.dispose();
108109
}
109110

@@ -534,7 +535,10 @@ class _PlaylistPageState extends State<PlaylistPage> {
534535
}
535536
}
536537

537-
void _updateSongsListOnRemove(int indexOfRemovedSong, dynamic songToRemove) {
538+
void _updateSongsListOnRemove(
539+
int indexOfRemovedSong,
540+
Map<String, dynamic> songToRemove,
541+
) {
538542
_originalPlaylistList.removeWhere((s) => s['ytid'] == songToRemove['ytid']);
539543
final playlistId = _playlist['ytid'];
540544
if (mounted) {

lib/services/common_services.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ List _deduplicateAndShuffle(List playlistSongs) {
215215
return uniqueSongs;
216216
}
217217

218-
Future<void> updateSongLikeStatus(dynamic songId, bool add) async {
218+
Future<void> updateSongLikeStatus(String songId, bool add) async {
219219
try {
220220
if (add) {
221221
if (!userLikedSongsList.any((song) => song['ytid'] == songId)) {
@@ -250,7 +250,7 @@ void moveLikedSong(int oldIndex, int newIndex) {
250250
}
251251

252252
Future<void> renameSongInLikedSongs(
253-
dynamic songId,
253+
String songId,
254254
String newTitle,
255255
String newArtist,
256256
) async {
@@ -276,13 +276,13 @@ Future<void> renameSongInLikedSongs(
276276
}
277277
}
278278

279-
bool isSongAlreadyLiked(songIdToCheck) =>
279+
bool isSongAlreadyLiked(String songIdToCheck) =>
280280
userLikedSongsList.any((song) => song['ytid'] == songIdToCheck);
281281

282-
bool isPlaylistAlreadyLiked(playlistIdToCheck) =>
282+
bool isPlaylistAlreadyLiked(String playlistIdToCheck) =>
283283
userLikedPlaylists.any((playlist) => playlist['ytid'] == playlistIdToCheck);
284284

285-
bool isSongAlreadyOffline(songIdToCheck) =>
285+
bool isSongAlreadyOffline(String songIdToCheck) =>
286286
userOfflineSongs.any((song) => song['ytid'] == songIdToCheck);
287287

288288
Map<String, dynamic> getOfflineSongByYtid(String ytid) {
@@ -618,7 +618,7 @@ Future<bool> makeSongOffline(dynamic song) async {
618618
}
619619
}
620620

621-
Future<bool> removeSongFromOffline(dynamic songId) async {
621+
Future<bool> removeSongFromOffline(String songId) async {
622622
try {
623623
final audioPath = FilePaths.getAudioPath(songId);
624624
final audioFile = File(audioPath);
@@ -700,7 +700,7 @@ Future<File?> _downloadAndSaveArtworkFile(String url, String filePath) async {
700700

701701
const recentlyPlayedSongsLimit = 250;
702702

703-
Future<void> updateRecentlyPlayed(dynamic songId) async {
703+
Future<void> updateRecentlyPlayed(String songId) async {
704704
try {
705705
if (userRecentlyPlayed.isNotEmpty &&
706706
userRecentlyPlayed.length == 1 &&
@@ -750,7 +750,7 @@ Future<void> updateRecentlyPlayed(dynamic songId) async {
750750
}
751751
}
752752

753-
Future<void> removeFromRecentlyPlayed(dynamic songId) async {
753+
Future<void> removeFromRecentlyPlayed(String songId) async {
754754
if (userRecentlyPlayed.any((song) => song['ytid'] == songId)) {
755755
userRecentlyPlayed.removeWhere((song) => song['ytid'] == songId);
756756
currentRecentlyPlayedLength.value = userRecentlyPlayed.length;

lib/services/playlists_manager.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ Future<List> _loadSongsForPlaylist(Map playlist) async {
848848
}
849849

850850
Future<List> getSongsFromPlaylist(
851-
dynamic playlistId, {
851+
String playlistId, {
852852
String? playlistImage,
853853
}) async {
854854
final songList = await getData('cache', 'playlistSongs$playlistId') ?? [];
@@ -884,8 +884,8 @@ Future updatePlaylistList(BuildContext context, String playlistId) async {
884884
}
885885

886886
Future<void> renameSongInPlaylist(
887-
dynamic playlistId,
888-
dynamic songId,
887+
String playlistId,
888+
String songId,
889889
String newTitle,
890890
String newArtist,
891891
) async {

lib/widgets/playlist_bar.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class PlaylistBar extends StatelessWidget {
4848
this.isAlbum = false,
4949
this.borderRadius = BorderRadius.zero,
5050
}) : playlistLikeStatus = ValueNotifier<bool>(
51-
isPlaylistAlreadyLiked(playlistId),
51+
playlistId != null && isPlaylistAlreadyLiked(playlistId),
5252
);
5353

5454
final Map? playlistData;

lib/widgets/song_bar.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class _SongBarState extends State<SongBar> {
324324
}
325325
} else if (widget.playlistId != null) {
326326
await renameSongInPlaylist(
327-
widget.playlistId,
327+
widget.playlistId!,
328328
_ytid,
329329
newTitle,
330330
newArtist,

0 commit comments

Comments
 (0)