@@ -1148,3 +1148,39 @@ void _unpinPlaylist(String playlistId) {
11481148 pinnedPlaylistIds.value = updated;
11491149 unawaited (addOrUpdateData ('user' , 'pinnedPlaylistIds' , updated));
11501150}
1151+
1152+ /// Updates the offline playlist metadata (title, image, source) when a custom
1153+ /// playlist is renamed or modified. This ensures the offline playlist section
1154+ /// in the library displays the updated information.
1155+ Future <void > syncOfflinePlaylistMetadata (Map updatedPlaylist) async {
1156+ final playlistId = updatedPlaylist['ytid' ]? .toString ();
1157+ if (playlistId == null ||
1158+ ! offlinePlaylistService.isPlaylistDownloaded (playlistId)) {
1159+ return ;
1160+ }
1161+
1162+ final offlinePlaylists = List <dynamic >.from (
1163+ offlinePlaylistService.offlinePlaylists.value,
1164+ );
1165+ final offlineIndex = offlinePlaylists.indexWhere (
1166+ (p) => p['ytid' ]? .toString () == playlistId,
1167+ );
1168+
1169+ if (offlineIndex == - 1 ) return ;
1170+
1171+ // Update the offline playlist with the new metadata
1172+ offlinePlaylists[offlineIndex] = {
1173+ ...offlinePlaylists[offlineIndex],
1174+ 'title' : updatedPlaylist['title' ],
1175+ 'image' : updatedPlaylist['image' ],
1176+ 'source' : updatedPlaylist['source' ],
1177+ };
1178+
1179+ // Create a new list to trigger ValueNotifier listeners
1180+ offlinePlaylistService.offlinePlaylists.value = List <dynamic >.from (
1181+ offlinePlaylists,
1182+ );
1183+ unawaited (
1184+ addOrUpdateData ('userNoBackup' , 'offlinePlaylists' , offlinePlaylists),
1185+ );
1186+ }
0 commit comments