getChannels method Null safety

  1. @override
Future<List<Channel>> getChannels(
  1. {List<Language>? lang,
  2. int limit = 25,
  3. int offset = 0,
  4. Order order = Order.ascending,
  5. Organization? organization,
  6. List<ChannelSort> sort = const [ChannelSort.organization]}
)

Get channels

Arguments:

  • lang 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 limit
  • offset Offset results
  • order Order.ascending or Order.descending order, default ascending.
  • organization If set, filter for Vtubers belonging to a specific org
  • sort 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>? lang,
  int limit = 25,
  int offset = 0,
  Order order = Order.ascending,
  Organization? organization,
  List<ChannelSort> sort = 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(sort, params);

  // Add the languages to filter by
  _addLanguages(lang, 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>`
}