nepal_address_flutter 0.1.1
nepal_address_flutter: ^0.1.1 copied to clipboard
Flutter UI widgets and form fields for cascading Nepal province, district, local level, and ward selection with bilingual support.
nepal_address_flutter #
Flutter UI components and Form fields for selecting Nepal's administrative divisions (Province, District, Local Level, and Ward) with cascading dependency, bilingual labels, and customizable styling.
Built on top of nepal_address.
Features #
- Cascading Selection: Automatically filters downstream options (Province -> District -> Local Level -> Ward) and resets child selections when parents change without losing widget state.
- Form Integration:
NepalAddressFormFieldintegrates seamlessly into FlutterFormwidgets with automatic validation, save/reset actions, and multilingual error messages. - Standalone Dropdowns: Individual
ProvinceDropdown,DistrictDropdown,LocalLevelDropdown, andWardDropdownwidgets for customized layouts. - Bilingual & Multilingual: Supports English (
english), Nepali (nepali), and Bilingual (bilingual—English / नेपाली) label displays. - Flexible Visibility: Hide or show individual administrative levels with deterministic fallback rules.
- Accessible & Customizable: Built on
DropdownButtonFormFieldwith stable item keys, accessibility semantics labels, and fullInputDecorationtheming.
Installation #
Add nepal_address_flutter to your pubspec.yaml:
dependencies:
nepal_address_flutter: ^0.1.0
Import the package in your Flutter widget files:
import 'package:nepal_address_flutter/nepal_address_flutter.dart';
Quick Start #
1. NepalAddressFormField (Form Integration) #
Integrate address selection directly into a Flutter Form with built-in validation:
final _formKey = GlobalKey<FormState>();
SelectedAddress? _savedAddress;
@override
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: Column(
children: [
NepalAddressFormField(
showWard: true,
language: NepalAddressLanguage.bilingual,
requiredLevels: const {
NepalAddressLevel.province,
NepalAddressLevel.district,
NepalAddressLevel.localLevel,
NepalAddressLevel.ward,
},
onSaved: (address) {
_savedAddress = address;
},
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
if (_formKey.currentState?.validate() ?? false) {
_formKey.currentState?.save();
print('Saved Address: ${_savedAddress?.en}');
print('JSON: ${_savedAddress?.toJson()}');
}
},
child: const Text('Submit'),
),
OutlinedButton(
onPressed: () => _formKey.currentState?.reset(),
child: const Text('Reset'),
),
],
),
);
}
2. NepalAddressPicker (Cascading Picker) #
Use NepalAddressPicker directly for controlled or uncontrolled cascading selection:
NepalAddressPicker(
showWard: true,
language: NepalAddressLanguage.english,
initialValue: const SelectedAddress(provinceId: 1),
onChanged: (SelectedAddress address) {
print('Selected English: ${address.en}');
print('Selected Nepali: ${address.np}');
print('Selected Bilingual: ${address.bilingual}');
},
)
3. Standalone Dropdowns #
For custom layouts or isolated dropdown requirements, use the four standalone widgets directly:
Province? selectedProvince;
District? selectedDistrict;
LocalLevel? selectedLocalLevel;
int? selectedWard;
// 1. Province Dropdown
ProvinceDropdown(
value: selectedProvince,
language: NepalAddressLanguage.english,
onChanged: (province) {
setState(() {
selectedProvince = province;
selectedDistrict = null;
selectedLocalLevel = null;
selectedWard = null;
});
},
),
// 2. District Dropdown (disabled if province is null)
DistrictDropdown(
province: selectedProvince,
value: selectedDistrict,
language: NepalAddressLanguage.english,
onChanged: (district) {
setState(() {
selectedDistrict = district;
selectedLocalLevel = null;
selectedWard = null;
});
},
),
// 3. Local Level Dropdown (disabled if district is null)
LocalLevelDropdown(
district: selectedDistrict,
value: selectedLocalLevel,
language: NepalAddressLanguage.english,
onChanged: (localLevel) {
setState(() {
selectedLocalLevel = localLevel;
selectedWard = null;
});
},
),
// 4. Ward Dropdown (disabled if localLevel is null)
WardDropdown(
localLevel: selectedLocalLevel,
value: selectedWard,
language: NepalAddressLanguage.english,
onChanged: (ward) {
setState(() {
selectedWard = ward;
});
},
),
Hidden-Level Rules #
When hiding administrative levels in NepalAddressPicker or NepalAddressFormField, the following deterministic rules apply:
- Hidden Parent via Initial Value: If a hidden parent is provided via
initialValueorvalue, it is used to filter child dropdown items. showDistrict: true, showProvince: false: A province is not required to list districts. The dropdown displays all 77 districts, and the province is automatically derived and populated when the user selects a district.showLocalLevel: true, showDistrict: false: RequiresshowDistrict: trueor an initialdistrictIdprovided ininitialValue/value. In debug builds, an assertion error is thrown if no initial district is provided ("showLocalLevel requires showDistrict or an initial districtId").showWard: true, showLocalLevel: false: RequiresshowLocalLevel: trueor an initiallocalLevelIdprovided ininitialValue/value. In debug builds, an assertion error is thrown if no initial local level is provided ("showWard requires showLocalLevel or an initial localLevelId").- Validation of Hidden Levels: Hidden levels are never required in validation, even if included in
requiredLevels.
Language Options #
Configure dropdown labels and list items via the language property:
NepalAddressLanguage.english: Shows English names (e.g. "Koshi Province", "Bhojpur", "Ward 1").NepalAddressLanguage.nepali: Shows Nepali Devanagari names with Devanagari numerals (e.g. "कोशी प्रदेश", "भोजपुर", "वडा नं. १").NepalAddressLanguage.bilingual: Displays bilingual titles and item entries (e.g. "Koshi Province / कोशी प्रदेश", "Ward 1 (वडा नं. १)").
Customization #
- Per-Level Decoration: Provide custom
InputDecorationfor each dropdown (provinceDecoration,districtDecoration,localLevelDecoration,wardDecoration). - Spacing & Orientation: Adjust
spacing(default:16.0) anddirection(Axis.verticalorAxis.horizontal). - Validation Messages: Customize missing level error strings using
requiredMessage.
Search & Aliases #
The core search engine is exported directly:
final results = NepalAddress.search('Patan');
- Ranking Order: Results rank by
exact>prefix>wordPrefix>contains>fuzzy. Within equal match type and score, primary names rank before aliases, followed by shorter text, higher level, and alphabetical tie-break. - Aliases: Spelling variants and old names are resolved through aliases. For example, searching
"Patan"returns two distinct exact matches with their full hierarchical paths:Patan, Baitadi, Sudurpaschim Province(Patan Municipality in Baitadi, primary name match)Lalitpur, Lalitpur, Bagmati Province(common name of Lalitpur city, alias match)
Because primary-name matches rank before alias matches for the same match type and score, Patan (Baitadi) ranks first and Lalitpur ranks second.
Dataset Provenance #
Cross-checked from three open MIT-licensed sources (sagautam5/local-states-nepal, younginnovations/nepal-locallevel-map, bedbyaspokhrel/nepal-geo-data). Not an official government dataset. 12 known source conflicts are listed as unverified.
See VERIFICATION.md for detailed conflict listings, pending matches, and verification status, and THIRD_PARTY_NOTICES.md for complete upstream dataset credits and licenses.
- Dataset Counts & Metadata: Read counts and release dates programmatically from
NepalAddress.dataInfo(e.g.NepalAddress.dataInfo.releaseDate,NepalAddress.provinces.length,NepalAddress.districts.length,NepalAddress.localLevels.length,NepalAddress.wards.length). - Wards: Wards are numbered 1..wardCount per local level. No ward names, codes or boundaries are included.
- IDs: IDs are this package's own and stable within a major version. They are not official government codes.
Known Limitations #
- Not Official: Not an official government dataset.
- No Geometry: Does not include map coordinates, boundaries, or GeoJSON geometry.
- Source Dataset Discrepancies: Names come from source datasets, so the same city can be spelled differently at different administrative levels (for example, Kathmandu district is spelled
काठमाडौँwhile the local level is spelledकाठमाण्डौंin Nepali). - Unverified Conflicts: Discrepancies between upstream datasets are recorded in
DataInfo.verification.unverifiedConflictsand detailed in VERIFICATION.md.
Version Compatibility #
- Dart SDK:
>=3.9.0 <4.0.0 - Flutter:
>=3.35.0
Contributing #
Please see CONTRIBUTING.md for bug reports, widget proposals, and guidelines for testing.