getCorrection method

Future<List<Track>> getCorrection({
  1. required String track,
  2. required String artist,
})

Use the last.fm corrections data to check whether the supplied artist has a correction to a canonical artist.

https://www.last.fm/api/show/artist.getCorrection

Implementation

Future<List<Track>> getCorrection({
  required String track,
  required String artist,
}) async {
  final parameters = {'track': track, 'artist': artist};

  final request = Request(
    api: _api,
    method: 'track.getCorrection',
    parameters: parameters,
  );

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

  final corrections = response['corrections'];

  if (corrections is List) {
    return List.generate(
      corrections.length,
      (i) =>
          Track.fromJson(response['corrections']['correction']['track'][i]),
    );
  }

  // A list of a single correction.
  return [Track.fromJson(corrections['correction']['track'])];
}