Skip to content

Commit

Permalink
option to add song at specific index of playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas24689 committed Oct 2, 2023
1 parent b7f745e commit 0556f3a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/API/musify.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,16 @@ String createCustomPlaylist(
return '${context.l10n()!.addedSuccess}!';
}

String addSongInCustomPlaylist(String playlistName, dynamic song) {
String addSongInCustomPlaylist(String playlistName, dynamic song, {int? indexToInsert}) {
final customPlaylist = userCustomPlaylists.firstWhere(
(playlist) => playlist['title'] == playlistName,
orElse: () => null,
);

if (customPlaylist != null) {
final List<dynamic> playlistSongs = customPlaylist['list'];
playlistSongs.add(song);
indexToInsert != null ? playlistSongs.insert(indexToInsert, song) :
playlistSongs.add(song);
addOrUpdateData('user', 'customPlaylists', userCustomPlaylists);
return 'Song added to custom playlist: $playlistName';
} else {
Expand Down

0 comments on commit 0556f3a

Please sign in to comment.