createPlaylist method
userId
- the Spotify user ID
playlistName
- the name of the new playlist
public
- Defaults to true
. If true
the playlist will be public,
if false
it will be private.
collaborative
- Defaults to false
. If true
the playlist will
be collaborative.
description
- the description of the new playlist
Implementation
Future<Playlist> createPlaylist(String userId, String playlistName,
{bool? public, bool? collaborative, String? description}) async {
final url = 'v1/users/$userId/playlists';
final json = <String, dynamic>{'name': playlistName};
if (public != null) json['public'] = public;
if (collaborative != null) json['collaborative'] = collaborative;
if (description != null) json['description'] = description;
final playlistJson = await _api._post(url, jsonEncode(json));
return Playlist.fromJson(jsonDecode(playlistJson));
}