๐ฆ pincode_address_picker
A complete Flutter package to pick and validate Country โ State โ City using dropdowns or typeaheads, or auto-fill them by entering a pincode/postal code.
Perfect for apps that collect addresses: e-commerce, delivery, registration, checkout, etc.
โจ Features
- ๐ Pincode to City/State auto-detection
- ๐ Built-in dataset of countries, states, and cities (with lat/lng and postal info)
- ๐งฉ Customizable UI layouts (4x1 column or 2x2 grid)
- ๐ฏ RegEx-based validation for postal codes by country
- ๐ง Exposed utility APIs if you want to use your own UI
- โก Fast, offline lookups with no runtime API calls
๐ Getting Started
1. Add to pubspec.yaml
dependencies:
pincode_country_state_city_pro: ^0.1.0
2. Usage
Using the default picker UI
final controller = AddressPickerController();
PincodeCountryStateCityPicker(
controller: controller,
gridType: GridType.grid4x1, // or GridType.grid2x2
showCountryFlag: true //show the country flag
)
|
|
๐ผ Layout Options
Support two pre-defined layouts:
GridType.grid4x1 โ All fields in vertical column
GridType.grid2x2 โ 2ร2 compact grid
๐ AddressPickerController
This controller helps you manage and listen to the selected country, state, city, and pincode.
final controller = AddressPickerController();
controller.selectedCountry.addListener(() {
print(controller.selectedCountry.value?.name);
});
Get selected values
controller.selectedCountry.value;
controller.selectedState.value;
controller.selectedCity.value;
๐งช If You Want Only the Data
You can use the utility APIs without the picker UI.
๐บ Get Countries
List<Country> countries = await getAllCountries();
Country? india = await getCountryByIsoCode(isoCode: "IN");
๐ Get States
List<StateModel> states = await getStatesOfCountry(countryCode: "IN");
StateModel? state = await getStateByCode(countryCode: "IN", stateCode: "TG");
๐ก Get Cities
List<City> cities = await getCitiesOfState(countryCode: "IN", stateCode: "AP");
City? city = await getCityByPostalCode(postalCode: "502103", countryCode: "TG");
๐บ ๐ ๐ก Get Address(State, City) from postalCode
AddressData addressData = await getStateAndCityByPostalCode(postalCode: "502103", countryCode: "IN");
State state = addressData.state;
City city = addressData.city;
Get PostalCodeFormat from countryCode
PostalCodeFormat? postalCodeFormat = getPostalFormatFromCountryCode(countryCode : "IN");
For more APIs, check this file
Additional information
๐ Contributing : Found a bug? Want to add more data or improve UX? PRs are welcome!! Open issues, contribute, or star the repo ๐