getAddress static method
Returns a complete PCIC address for the given code set.
Implementation
static Future<Map<String, String?>> getAddress({
required String regionNo,
required String provinceCode,
required String municipalityCode,
required String barangayCode,
}) async {
final normalizedRegionNo = _normalizeValue(regionNo);
final normalizedProvinceCode = _normalizeValue(provinceCode);
final normalizedMunicipalityCode = _normalizeValue(municipalityCode);
final normalizedBarangayCode = _normalizeValue(barangayCode);
if (normalizedRegionNo == null ||
normalizedProvinceCode == null ||
normalizedMunicipalityCode == null ||
normalizedBarangayCode == null) {
return {
'regionNo': null,
'regionCode': null,
'regionSubCode': null,
'provinceCode': null,
'provinceName': null,
'municipalityCode': null,
'municipalityName': null,
'barangayCode': null,
'barangayName': null,
};
}
final barangays = await getBarangays(
regionNo: normalizedRegionNo,
provinceCode: normalizedProvinceCode,
municipalityCode: normalizedMunicipalityCode,
);
final matchedBarangay = barangays.cast<Map<String, dynamic>?>().firstWhere(
(barangay) =>
_normalizeValue(barangay?['barangayCode']) == normalizedBarangayCode,
orElse: () => null,
);
if (matchedBarangay == null) {
return {
'regionNo': null,
'regionCode': null,
'regionSubCode': null,
'provinceCode': null,
'provinceName': null,
'municipalityCode': null,
'municipalityName': null,
'barangayCode': null,
'barangayName': null,
};
}
return {
'regionNo': normalizedRegionNo,
'regionCode': _normalizeValue(matchedBarangay['regionCode']),
'regionSubCode': _normalizeValue(matchedBarangay['regionSubCode']),
'provinceCode': normalizedProvinceCode,
'provinceName': _normalizeValue(matchedBarangay['provinceName']),
'municipalityCode': normalizedMunicipalityCode,
'municipalityName': _normalizeValue(matchedBarangay['municipalityName']),
'barangayCode': normalizedBarangayCode,
'barangayName': _normalizeValue(matchedBarangay['barangayName']),
};
}