getTopAlbums method

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

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

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

Implementation

Future<List<Album>?> getTopAlbums({
  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.getTopAlbums',
    parameters: parameters,
  );

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

  final topAlbums = response['albums']['album'];

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