getTopTracks method
Get the top tracks by an artist on Last.fm, ordered by popularity.
Implementation
Future<List<Track>?> getTopTracks({
String? artist,
String? mbid,
int page = 1,
int limit = 50,
bool autoCorrect = false,
}) async {
if (artist == null && mbid == null) {
return Future.error(
ScrobblenautException(
description: 'This method requires at least artist or mbid.',
),
);
}
final parameters = {
'artist': artist,
'mbid': mbid,
'page': page,
'limit': limit,
'autocorrect': (autoCorrect ? 1 : 0),
};
final request = Request(
api: _api,
method: 'artist.getTopTracks',
parameters: parameters,
);
final response = await request.send(mode: RequestMode.GET);
final topTracks = response['toptracks']['track'];
return topTracks == null
? null
: List.generate(
(topTracks as List).length,
(i) => Track.fromJson(topTracks[i]),
);
}