getTopTracks method
Get the most popular tracks on Last.fm last week by country.
Implementation
Future<List<Track>> getTopTracks({
required String country,
String? location,
int page = 1,
int limit = 50,
}) async {
final parameters = {
'country': country,
'location': location,
'page': page,
'limit': limit,
};
final request = Request(
api: _api,
method: 'geo.getTopTracks',
parameters: parameters,
);
final response = await request.send(mode: RequestMode.GET);
final topTracks = response['tracks']['track'];
if (topTracks == null) {
return [];
} else {
// This operation is necessary because the tracks have different duration.
var fixTopTracks = List.generate(
(topTracks as List).length,
(i) => Track.fromJson(topTracks[i]),
);
for (var track in fixTopTracks) {
track.duration = track.duration != null ? track.duration! * 1000 : null;
}
return fixTopTracks;
}
}