getAddress static method
Original method - Get complete address by codes
Implementation
static Future<Map<String, String?>> getAddress({
required String provinceCode,
required String municipalityCode,
required String barangayCode,
}) async {
await AddressData.loadData();
final barangay = AddressData.barangays?.firstWhere(
(b) =>
b['provinceCode'].toString() == provinceCode &&
b['municipalityCode'].toString() == municipalityCode &&
b['barangayCode'].toString() == barangayCode,
orElse: () => null,
);
if (barangay == null) {
return {
'regionCode': null,
'regionSubCode': null,
'provinceName': null,
'municipalityName': null,
'barangayName': null,
};
}
final regionCode = barangay['regionCode'].toString();
final province = _findProvinceByCode(provinceCode, regionCode: regionCode);
final municipality = AddressData.municipalities?.firstWhere(
(m) =>
m['regionCode'].toString() == regionCode &&
m['provinceCode'].toString() == provinceCode &&
m['municipalityCode'].toString() == municipalityCode,
orElse: () => null,
);
return {
'regionCode': regionCode,
'regionSubCode':
_getRegionSubCode(province) ??
_sanitizeRegionValue(barangay['regionSubCode']),
'provinceName': province?['provinceName'] ?? barangay['provinceName'],
'municipalityName':
municipality?['municipalityName'] ?? barangay['municipalityName'],
'barangayName': barangay['barangayName'],
};
}