restcountries 0.0.2

A library to get countries, state/region, and cities.

This library will help you out to get the ease of loading countries, state/regions, and cities from So before you use this library, make sure you already have the API key obtained on the website. Once you have that, you shall use this library freely.

Usage #

A simple usage example:

import 'package:restcountries/restcountries.dart';

main() async {
  var api = RestCountries.setup("YOUR_API_KEY");
  List<Country> countries = await api.getCountries();
  // see example for more details

Functionality #

Use CaseSupported
Get All CountriesYes
Get all regions based on country codeYes
Get all cities based on regions and country codeYes
Search CountryYes
Search regionYes
Check Quota (
Get postal codeNo

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Changelog #

0.0.1 (2019-07-22) #

New #

  • Initial rest countries package. [Mochamad Gufron]


import 'package:restcountries/restcountries.dart';

main() async {
  var api = RestCountries.setup("YOUR_API_KEY");
  List<Country> countries;
  List<Region> regions;
  List<City> cities;
  // get all countries
  countries = await api.getCountries();
  // or you could do this as long as you have called setup for initialization
  countries = await RestCountries.instance.getCountries();
  // search country functionality
  // you could also put city and/or region to narrow down the search of the country
  countries = await api.searchCountry(keyword: "Indo", city: "", region: "");

  // get all regions of a country. You need to pass the countryCode as it is required from the API
  regions = await api.getRegions(countryCode: "id");

  // search region
  regions =
      await api.searchRegion(countryCode: "id", city: "", keyword: "Jawa");

  // you could get all cities by just filling the countryCode and region name.
  // if you want to narrow it down to search of some city, put the keyword as parameter
  cities = await api.getCities(
      countryCode: "id", region: "Jawa Timur", keyword: "mal");

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  restcountries: ^0.0.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:restcountries/restcountries.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 13, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Health issues and suggestions

Document public APIs. (-0.30 points)

41 out of 42 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/models/city.dart. (-0.50 points)

Analysis of lib/src/models/city.dart reported 1 hint:

line 18 col 37: Unnecessary new keyword.

Fix lib/src/models/country.dart. (-0.50 points)

Analysis of lib/src/models/country.dart reported 1 hint:

line 12 col 37: Unnecessary new keyword.

Fix lib/src/models/region.dart. (-0.50 points)

Analysis of lib/src/models/region.dart reported 1 hint:

line 12 col 37: Unnecessary new keyword.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (dio).

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

The package description is too short. (-4 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
dio ^2.1.3 2.2.2 3.0.8
Transitive dependencies
cookie_jar 1.0.1
Dev dependencies
mockito 4.1.0
pedantic ^1.0.0
test ^1.0.0