fetchPosts method
Gets and returns a list of Posts
in this guild
Implementation
Future<List<Post>> fetchPosts({
SortType sortType = SortType.Hot,
required int page,
required int quantity,
}) async {
// Get posts from listing, determining how the posts should be sorted
// and which page the listing is to be extracted from
final response = await api.get('guild/$name/listing', headers: {
'sort': EnumToString.convertToString(sortType).toLowerCase(),
'page': page,
});
if (response == null) {
return [];
}
final body = jsonDecode(response.body);
// Converts _InternalLinkedHashMap<String, dynamic> to a List<dynamic> with all the posts
List<dynamic> rawPosts = Map<String, dynamic>.from(body)['data'];
return rawPosts.map((rawPost) => Post(api)..fetchData(rawPost)).toList();
}