getTopSingles method
Retrieves a list of an artist's top singles in a specific market.
artistId: The Spotify ID of the artist.
Returns a list of SimplifiedAlbum objects representing the artist's top singles.
Implementation
Future<List<SimplifiedAlbum>> getTopSingles(String artistId) async {
try {
// Make an API request to get artist's albums
final response = await _dio.get(
'https://api.spotify.com/v1/artists/$artistId/albums',
queryParameters: {
'include_groups': 'single',
'market': Market.AM.name, // Replace with the desired market
},
);
// Parse the response into a list of SimplifiedAlbum objects
final albums = (response.data['items'] as List)
.map((album) => SimplifiedAlbum.fromMap(album))
.toList();
return albums;
} catch (e) {
throw Exception('Error fetching top singles: $e');
}
}