getArticlesList method
Retrieves a list of articles from the API.
subcategoryIds
- The articles topics to be retrieved.
page
- The page number of the article list to retrieve. Defaults to 1.
perPage
- The number of articles items to retrieve per page. Defaults to 20.
Returns a list of consultation objects if the API call is successful.
Implementation
Future<List<Article>> getArticlesList(
{required List<int> subcategoryIds, int page = 1, int perPage = 20}) async {
final response = await callApi(
perPage: perPage,
page: page,
endpoint: 'https://rest-api.altibbi.com/active/v1/articles',
body: {
'filter[sub_category_id][in]': subcategoryIds,
'sort': '-article_id',
},
method: 'get');
if (response.statusCode == 200) {
final List<dynamic> responseData = json.decode(response.body);
final List<Article> articlesList =
responseData.map((json) => Article.fromJson(json)).toList();
return articlesList;
} else {
throw Exception('Error: ${response.body}');
}
}