getTopArtists method

Future<List<Artist>?> getTopArtists({
  1. required String tag,
  2. int page = 1,
  3. int limit = 50,
})

Get the top artists tagged by this tag, ordered by tag count.

https://www.last.fm/api/show/tag.getTopArtists

Implementation

Future<List<Artist>?> getTopArtists({
  required String tag,
  int page = 1,
  int limit = 50,
}) async {
  final parameters = {'tag': tag, 'page': page, 'limit': limit};

  final request = Request(
    api: _api,
    method: 'tag.getTopArtists',
    parameters: parameters,
  );

  final response = await request.send(mode: RequestMode.GET);

  final topArtists = response['topartists']['artist'];

  return topArtists == null
      ? null
      : List.generate(
          (topArtists as List).length,
          (i) => Artist.fromJson(topArtists[i]),
        );
}