getVideosRelatedToChannel method Null safety

  1. @override
Future<VideoFullList> getVideosRelatedToChannel(
  1. String channelId,
  2. {required VideoSearchType type,
  3. List<Includes>? includes,
  4. List<Language> languages = const [Language.all],
  5. int limit = 25,
  6. int offset = 0,
  7. bool paginated = true}
)

Get Videos Related To Channel

A simplified method for access channel specific data. If you want more customization, the same result can be obtained by calling the queryVideos() method.

Arguments

  • channelId ID of the Youtube Channel that is being queried
  • type The type of video resource to fetch. Clips finds clip videos of a vtuber channel, Video finds the channelId channel's uploads, and collabs finds videos uploaded by other channels that mention this channelId
  • includes Request extra data be included in the results. They are not guarenteed to be returned.
  • languages List of Language enum to filter channels/clips. Official streams do not follow this parameter
  • limit Result limit. Max of 50.
  • offset Offset results
  • paginated If paginated is set to true, returns VideoFullList with total, otherwise returns VideoFullList without the total.

Implementation

@override
Future<VideoFullList> getVideosRelatedToChannel(
  String channelId, {
  required VideoSearchType type,
  List<Includes>? includes,
  List<Language> languages = const [Language.all],
  int limit = 25,
  int offset = 0,
  bool paginated = true,
}) async {
  // Limit cannot be greater than 50 otherwise request will be denied
  assert(limit <= 50);

  final Map<String, dynamic> params = {};

  // Add the items with default values (they can't be null)
  params.addAll({
    'limit': '$limit',
    'offset': '$offset',
  });

  _addIncludes(includes, params);
  _addLanguages(languages, params);
  _addPaginated(paginated, params);

  final response = await get(path: '${_Constants.channelsPath}/$channelId/${EnumUtil.convertVideoSearchTypeToString(type)}', params: params);

  if (paginated) {
    // Grab total and return with it
    final videoList = VideoFullList.fromJson(response.body);
    return videoList.copyWith(paginated: true);
  }

  final List list = jsonDecode(response.body);
  return VideoFullList(videos: list.map((video) => VideoFull.fromMap(video)).toList());
}