rest_countries_data
एक डार्ट पैकेज जो REST Countries API के लिए एक वрапर के रूप में काम करता है, देशों के डेटा तक आसान पहुंच प्रदान करता है।
एक डार्ट पैकेज जो REST Countries API के लिए एक वрапर के रूप में काम करता है, देशों के डेटा तक आसान पहुंच प्रदान करता है।
यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।
rest_countries_data Logo
A Dart wrapper around the REST Countries v3.1 API that provides a fully-typed, developer-friendly interface for accessing detailed country data.
CountryModel to map the API responseCountryFields selector for fine-grained queriesAdd to your pubspec.yaml:
dependencies:
rest_countries_data: ^1.0.0
Then run:
# For Dart users
dart pub get
# For Flutter users
flutter pub get
import 'package:rest_countries_data/rest_countries_data.dart';
final countries = await RestCountries.getAllCountries(
fields: [CountryFields.name, CountryFields.capital, CountryFields.region],
);
When using the fields parameter in methods like getAllCountries, the maximum number of allowed fields is 10. This limit is enforced by the REST Countries API.
Also note: Whenever you specify the fields property, the properties that will be available in the returned CountryModel depend entirely on which CountryFields you request. If you omit a field, the corresponding property in CountryModel may be null.
final country = await RestCountries.getCountryByCapital(capital: 'Paris');
final country = await RestCountries.getCountryByCode(code: 'NG');
final countries = await RestCountries.getCountriesByCurrency(currency: 'USD');
final countries = await RestCountries.getCountriesByRegion(region: 'Europe');
final countries = await RestCountries.getCountriesBySubRegion(subRegion: 'Eastern Africa');
final country = await RestCountries.getCountryByFullName(fullName: 'Federal Republic of Nigeria');
final countries = await RestCountries.getCountriesByLanguage(language: 'en');
final countries = await RestCountries.getCountriesByDemonym(demonym: 'Nigerian');
final countries = await RestCountries.getCountriesByTranslation(translation: 'Niger');
final countries = await RestCountries.getCountriesByIndependentStatus(
independent: true,
fields: [CountryFields.name, CountryFields.flag],
);
class CountryModel {
final Name? name;
final List<String>? capital;
final String? region;
final String? subregion;
final Map<String, dynamic>? flags;
// ...
}
class Name {
final String common;
final String official;
final Map<String, NativeName>? nativeName;
}
Use the CountryFields enum to limit which fields are returned from the API:
CountryFields.name
CountryFields.capital
CountryFields.region
CountryFields.area
CountryFields.languages
// etc.
Note: Maximum 10 fields per request for getAllCountries()
getCountryPhoneNumberCodeThis convenience getter is available on the CountryModel and returns the full numeric dialing code (e.g., +234 for the country Nigeria). It is constructed by combining idd.root and idd.suffixes in the CountryModel.
| Method | Description |
|---|---|
getAllCountries({required fields}) |
Get all countries with selected fields |
getCountryByCapital({required capital}) |
Filter by capital city |
getCountryByCode({required code}) |
Get a single country by ISO code |
getCountriesByCodes({required codes}) |
Get multiple countries by ISO codes |
getCountriesByCurrency({required currency}) |
Filter by currency |
getCountriesByDemonym({required demonym}) |
Filter by demonym |
getCountriesByLanguage({required language}) |
Filter by spoken language |
getCountriesByRegion({required region}) |
Filter by region |
getCountriesBySubRegion({required subRegion}) |
Filter by subregion |
getCountriesByTranslation({required translation}) |
Filter by translated country name |
getCountryByFullName({required fullName}) |
Get a country by its full name |
getCountriesByName({required name}) |
Filter by partial or full name |
getCountriesByIndependentStatus(...) |
Filter by independence and optionally fields |
CountryModel.getCountryPhoneNumberCode |
Get the phone dialing code of a country (e.g. +234) |
import 'package:rest_countries_data/rest_countries_data.dart';
void main() async {
final countries = await RestCountries.getCountriesByRegion(region: 'Africa');
for (var country in countries) {
print(country.name?.common);
}
}
Pull requests are welcome! If you have ideas or find bugs, feel free to open an issue.
After cloning the repository, install the git hooks for automatic formatting and linting:
./install-hooks.sh
This will set up a pre-commit hook that:
Maintained by Franklin Oladipo