getTehsilDistrict function

String? getTehsilDistrict(
  1. String tehsil, [
  2. String? province
])

Returns the district a tehsil (taluka, sub-division) was in at the 2023 census, or null. Matching is case-insensitive.

Census-district caveat: the result is the census district, which may have been split since (a tehsil of Quetta is now in Quetta East or Quetta West). A few names are shared by tehsils in different districts (Saddar, Sahiwal, Khanpur); pass the province to tell them apart. Returns null when the name is unknown or still matches more than one district.

Implementation

String? getTehsilDistrict(String tehsil, [String? province]) {
  final key = normalizeKey(tehsil);
  if (key.isEmpty) return null;
  final provinceKey = province == null ? null : normalizeKey(province);
  final matches = {
    for (final e in tehsils)
      if (normalizeKey(e.tehsil) == key &&
          (provinceKey == null || normalizeKey(e.province) == provinceKey))
        e.censusDistrict,
  };
  return matches.length == 1 ? matches.first : null;
}