REST Countries API를 래핑하여 글로벌 국가 데이터에 대한 접근을 간소화하는 Dart 패키지입니다. 이름, 국기, 국경, 화폐 등 국가에 대한 상세 정보를 가져오기 위한 깔끔하고 사용하기 쉬운 인터페이스를 제공합니다. Flutter 애플리케이션에서 신뢰할 수 있고 최신의 국가 데이터가 필요한 개발자를 위해 설계되었으며, 다양한 플랫폼을 지원하고 부가 코드를 줄입니다. 패키지는 내부적으로 HTTP 요청을 처리하고 원활한 통합을 위한 구조화된 데이터를 반환합니다.
사용 사례
여행 앱에서 국가 정보 가져오기
언어 또는 통화 선택기 만들기
국가 국기 및 지도 표시
세계 뉴스 또는 인구 통계 대시보드 만들기
사용자 위치 선택 구현
주요 기능
간단한 API 래퍼
다수의 플랫폼을 지원합니다
구조화된 국가 데이터를 반환합니다
내부적으로 HTTP 요청을 처리합니다
Flutter와의 간편한 통합
적합한 대상
국제 앱을 구축하는 Flutter 개발자
국가 메타데이터가 필요한 앱
교육 또는 참고 애플리케이션
여행 및 로컬라이제이션 도구
고려 사항
인터넷 연결이 필요합니다
REST 국가 API 데이터에 제한됨
오프라인 캐싱 포함되지 않음
외부 API 사용 가능 여부에 따라 다릅니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
rest_countries_data
A Dart wrapper around the REST Countries v3.1 API that provides a fully-typed, developer-friendly interface for accessing detailed country data.
✨ Features
Get all countries with selected fields (limited to 10 fields)
Query countries by:
Capital
Full name or partial name
ISO 3166-1 code or list of codes
Region / Subregion
Language / Currency / Demonym
Translation
Independence status
Built-in CountryModel to map the API response
Enum-based CountryFields selector for fine-grained queries
Clean separation of concerns via Repository, API and Domain layers
🚀 Getting Started
1. Install the Package
Add 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
final countries = awaitRestCountries.getAllCountries(
fields: [CountryFields.name, CountryFields.capital, CountryFields.region],
);
Field Limitation ⚠️
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.
Get Countries by Capital
final country = awaitRestCountries.getCountryByCapital(capital: 'Paris');
Get a Country by ISO Code
final country = awaitRestCountries.getCountryByCode(code: 'NG');
Get Countries by Currency
final countries = awaitRestCountries.getCountriesByCurrency(currency: 'USD');
Get Countries by Region
final countries = awaitRestCountries.getCountriesByRegion(region: 'Europe');
Get Countries by SubRegion
final countries = awaitRestCountries.getCountriesBySubRegion(subRegion: 'Eastern Africa');
Get Country by Full Name
final country = awaitRestCountries.getCountryByFullName(fullName: 'Federal Republic of Nigeria');
Get Countries by Language, Demonym, or Translation
final countries = awaitRestCountries.getCountriesByLanguage(language: 'en');
final countries = awaitRestCountries.getCountriesByDemonym(demonym: 'Nigerian');
final countries = awaitRestCountries.getCountriesByTranslation(translation: 'Niger');
Get Countries by Independence Status
final countries = awaitRestCountries.getCountriesByIndependentStatus(
independent: true,
fields: [CountryFields.name, CountryFields.flag],
);
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()
🧩 Utility Getter
getCountryPhoneNumberCode
This 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.
🔍 API Overview
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)
📊 Example (Run it)
import'package:rest_countries_data/rest_countries_data.dart';
voidmain() async {
final countries = awaitRestCountries.getCountriesByRegion(region: 'Africa');
for (var country in countries) {
print(country.name?.common);
}
}
🚪 Contributing
Pull requests are welcome! If you have ideas or find bugs, feel free to open an issue.
Development Setup
After cloning the repository, install the git hooks for automatic formatting and linting: