getTopHeadlines method
Fetches a list of top headlines based on the provided query parameters.
Optional parameters:
country
: The 2-letter ISO 3166-1 code of the country to retrieve headlines for.category
: The category of articles to retrieve.sources
: A comma-separated list of source IDs or domains.query
: The search query.pageSize
: The number of articles per page.page
: The page number to retrieve.
Implementation
Future<List<Article>> getTopHeadlines({
String? country,
String? category,
String? sources,
String? query,
int? pageSize,
int? page,
}) async {
final String url = Util.buildTopHeadlinesUrl(
country,
category,
sources,
query,
pageSize,
page,
);
final dynamic response = await Util.call(
apiKey: apiKey,
url: url,
dataKey: "articles",
);
return Article.parseList(response);
}