newsapi 1.0.0 copy "newsapi: ^1.0.0" to clipboard
newsapi: ^1.0.0 copied to clipboard

outdated

Use the NewsApi v2 service in Dart. The library has a clear return structure and an easy-to-use API.

NewsApi #

Use NewsApi service with Dart

Install #

dependencies: newsapi: any

Example #

  var newsApi = NewsApi();
  newsApi.init(
//    dioOptions: dioOptions,
//    interceptors: interceptors,
    debugLog: true,
    apiKey: 'foo',
  );
  
  newsApi.apiKey = 'bar';

  print(await newsApi.topHeadlines(
//    country: country,
//    category: category,
//    sources: sources,
//    q: q,
    language: 'en',
//    pageSize: pageSize,
//    page: page,
  ));
  print(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(await newsApi.sources(
//    category: category,
//    language: language,
//    country: country,
      ));

Response Structure #

class BaseResponse extends Equatable {
  String code;
  String message;
  @JsonKey(
    fromJson: statusFromJson,
    toJson: statusToJson,
  )
  bool status;
  int totalResults;
}

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

class Source extends Equatable {
  String category;
  String country;
  String description;
  String id;
  String language;
  String name;
  String url;
}

Start Test #

Modify test / api_key.dart

const API_KEY = 'API_KEY';

and start

flutter --no-color test --machine test/newsapi_test.dart
10
likes
0
pub points
41%
popularity

Publisher

verified publisheryeungkc.com

Use the NewsApi v2 service in Dart. The library has a clear return structure and an easy-to-use API.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

dio, equatable, flutter, json_annotation, pretty_dio_logger, retrofit

More

Packages that depend on newsapi