getUserTopItems<T> method
Gets the current user's top tracks or artists.
type should be either 'tracks' or 'artists'.
Implementation
Future<List<T>> getUserTopItems<T>({
required String type,
String timeRange = 'medium_term',
int limit = 20,
required T Function(Map<String, dynamic>) fromJson,
}) async {
final params = {
'time_range': timeRange,
'limit': limit.toString(),
};
final url = Uri.https(_baseApiHost, '/v1/me/top/$type', params);
final json = await _getJson(url);
final items = json['items'] as List<dynamic>;
return items.map((item) => fromJson(item as Map<String, dynamic>)).toList();
}