requestMapByCategory method
request random media (images and/or videos) for a list of categories
Implementation
Stream<Map<String, Map<MediaType, PixabayResponse>>> requestMapByCategory(
{int photoResultsPerCategory,
int videoResultsPerCategory,
List<String> categories}) async* {
for (int i = 0; i < Category.categories.length; i++) {
PixabayResponse resVideo;
PixabayResponse resImage;
if (categories == null ||
categories.indexOf(Category.categories[i]) >= 0) {
String category = Category.categories[i];
if (photoResultsPerCategory != null)
resImage = await requestImages(
resultsPerPage: photoResultsPerCategory, category: category);
if (photoResultsPerCategory != null)
resVideo = await requestVideos(
resultsPerPage: videoResultsPerCategory, category: category);
yield Map.from({
category: {MediaType.photo: resImage, MediaType.video: resVideo}
});
}
}
}