newsapi

Last updated:

0 purchases

newsapi Image
newsapi Images
Add to Cart

Description:

newsapi

NewsApi #



Use NewsApi service with Dart
Install #
dependencies:
newsapi: ^1.0.9
copied to clipboard
Example #
var newsApi = NewsApi(
// dioOptions: dioOptions,
// interceptors: interceptors,
debugLog: true,
apiKey: 'foo',
);


newsApi.apiKey = 'Change_your_api_key';

ArticleResponse topHeadlines = await newsApi.topHeadlines(
// country: country,
// category: category,
// sources: sources,
// q: q,
language: 'en',
// pageSize: pageSize,
// page: page,
);
print(topHeadlines);
ArticleResponse everything = await newsApi.everything(
q: 'flutter',
// qInTitle: qInTitle,
// sources: sources,
// domains: domains,
// excludeDomains: excludeDomains,
// from: from, // support DateTime or String
// to: to, // support DateTime or String
// language: language,
// sortBy: sortBy,
// pageSize: pageSize,
// page: page,
);
print(everything);
SourceResponse sources = await newsApi.sources(
// category: category,
// language: language,
// country: country,
);
print(sources);
copied to clipboard
Response Structure #
class BaseResponse extends Equatable {
String code;
String message;
@JsonKey(
fromJson: statusFromJson,
toJson: statusToJson,
)
bool status;
int totalResults;
}

class ArticleResponse extends BaseResponse {
List<Article> articles;
}

class Article extends Equatable {
Source source;
String author;
String content;
String description;
DateTime publishedAt;
String title;
String url;
String urlToImage;
}

class SourceResponse extends BaseResponse {
List<Source> sources;
}

class Source extends Equatable {
String category;
String country;
String description;
String id;
String language;
String name;
String url;
}
copied to clipboard
Start Test #
API_KEY=YOUR_API_KEY pub run test
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.