getChannels method Null safety
Get channels
Arguments:
languages
List of languages. Language is a property of Channel, so only Channels satisfying the language will be returned. Leave empty to search for Vtubers and/or all clippers.limit
Results limitoffset
Offset resultsorder
Order.ascending or Order.descending order, default ascending.organization
If set, filter for Vtubers belonging to a specific orgchannelSort
Column to sort on, leave default to use ChannelSort.organization as sort. Theoretically any value in ChannelSort should work
Implementation
@override
Future<List<Channel>> getChannels({
List<Language>? languages,
int limit = 25,
int offset = 0,
Order order = Order.ascending,
String? organization,
List<ChannelSort> channelSort = const [ChannelSort.organization],
}) async {
// According to API docs, the maximum accepted value is 50 and anything higher the request will be denied
assert(limit <= 50);
// Create the params list
final Map<String, dynamic> params = {};
// Add the items with default values (they can't be null)
params.addAll({
'limit': '$limit',
'offset': '$offset',
'order': EnumUtil.convertOrderToString(order),
});
_addChannelSort(channelSort, params);
// Add the languages to filter by
_addLanguages(languages, params);
// Add the organization param
_addSingleOrganization(organization, params);
final response = await get(path: _Constants.channelsPath, params: params);
final List list = jsonDecode(response.body);
return list
.map((channel) => Channel.fromMap(channel))
.toList(); // Returns as `List<Channel>`
}