getUserPlaylists method

Future<List<SimplifiedPlaylist>> getUserPlaylists()

Retrieves a list of the current user's playlists.

Returns a list of SimplifiedPlaylist objects representing the user's playlists.

Implementation

Future<List<SimplifiedPlaylist>> getUserPlaylists() async {
  try {
    // Make an API request to get user playlists
    final response = await _dio.get(
      'https://api.spotify.com/v1/me/playlists',
    );
    final playlists = (response.data['items'] as List)
        .map((playlist) => SimplifiedPlaylist.fromMap(playlist))
        .toList();
    return playlists;
  } catch (e) {
    throw Exception('Error fetching user playlists: $e');
  }
}