country_io 1.0.0

countryIO #

A simple country.io data parser, written with ❤️ using Dart :)

Show some ❤️ by putting ⭐ :)

what does it do ? #

This Dart package can be used to fetch country data from country.io, which includes country iso2 code, country name, capital name, continent code, currency code & phone code, which will be eventually stored in a json encoded file, whose path needs to be provided to Generator class constructor.

how to use ? #

Well using this package for generating json encoded file, holding country data, is pretty much easy.

Simply invoke Generator constructor with a valid path to target data.json file. Calling Generator( ... ).generate(), will start fetching data from country.io, then parsing data and json encoding data for storing in target file.

This function will return a Future<Map<String, Map<String, String>>>, an empty Map denotes failure, otherwise full parsed data set will be returned in form of Map.

Every key of this map will be an iso2 country code, helping to identify a certain country uniquely.

{
     .
     .
     .
     iso2:
     {
        'continent': continent ?? '',
        'name': name ?? '',
        'iso3': iso3 ?? '',
        'capital': capital ?? '',
        'phone': phone ?? '',
        'currency': currency ?? '',
      }
     .
     .
     .
   }

And value for a certain iso2 country code will be another Map<String, String>, holding detailed country info.

Generator('./data.json')
    .generate()
    .then((result) => print(result.isNotEmpty ? 'Success' : 'Failed !!!'));

Yes, it's that simple 😉

courtesy #

Country data is fetched from country.io, so they do deserve courtesy.

For T&C of data utilization, you may be interested in taking a look at country.io

Hoping, it helped you a bit (o_o)

v1.0.0 #

what's working ? #

  • Can fetch country data from remote API
  • Can store in local file, if proper file path is provided
  • Generally will return fetched data in form of Map<String, Map<String, String>>, holding detailed data for all countries
  • Feel free to process received data more 😉

example/example.dart

import 'package:country_io/country_io.dart';

main() => Generator(
        targetPath:
            '../data/data.json') // make sure this path exists i.e. file may not exists, which can be created but you need to have directory already existing, otherwise operation will fail, by returning false
    // if you're not interested in storing it in any file, simply don't pass any argument for targetPath parameter
    .generate()
    .then((result) => print(result.isNotEmpty ? 'Success' : 'Failed !!!'));

Use this package as a library

1. Depend on it

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


dependencies:
  country_io: ^1.0.0

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:country_io/country_io.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
96
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

We analyzed this package on Sep 10, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:country_io/country_io.dart with components: io.

Health suggestions

Fix lib/generator/generator.dart. (-1 points)

Analysis of lib/generator/generator.dart reported 2 hints:

line 102 col 31: DO use curly braces for all flow control structures.

line 119 col 31: DO use curly braces for all flow control structures.

Fix lib/src/capital.dart. (-0.50 points)

Analysis of lib/src/capital.dart reported 1 hint:

line 8 col 26: Use = to separate a named parameter from its default value.

Fix lib/src/continent.dart. (-0.50 points)

Analysis of lib/src/continent.dart reported 1 hint:

line 8 col 28: Use = to separate a named parameter from its default value.

Fix additional 4 files with analysis or formatting issues. (-2 points)

Additional issues in the following files:

  • lib/src/currency.dart (1 hint)
  • lib/src/iso3.dart (1 hint)
  • lib/src/names.dart (1 hint)
  • lib/src/phone.dart (1 hint)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0