getRecentlyPlayed method

Future<List<Track>> getRecentlyPlayed({
  1. int? limit,
  2. String? after,
  3. String? before,
})

Returns the user's recently played tracks. You can specify limit, after (timestamp in ms), or before to paginate.

Implementation

Future<List<Track>> getRecentlyPlayed({
  int? limit,
  String? after,
  String? before,
}) async {
  final uri = Uri.https(
    _baseApiHost,
    '/v1/me/player/recently-played',
    {
      if (limit != null) 'limit': limit.toString(),
      if (after != null) 'after': after,
      if (before != null) 'before': before,
    },
  );

  final json = await _getJson(uri);
  final items = json['items'] as List;

  return items
      .map((item) => Track.fromJson(item['track'] as Map<String, dynamic>))
      .toList();
}