getPlaceByIranNationalId function

NationalIdPlace? getPlaceByIranNationalId(
  1. String nationalId
)

Gives the place information based on the given String as national id

Implementation

NationalIdPlace? getPlaceByIranNationalId(String nationalId) {
  if (!nationalId.isIranianNationalId) return null;

  print('its national id');

  final code = nationalId.substring(0, 3);
  final find = nationalIdPlaces.firstWhere(
    (place) => place?.codesAsString.contains(code) ?? false,
    orElse: () => null,
  );

  print('find object: $find');

  if (find != null) {
    final nationalIdProvince =
        provinces.firstWhere((province) => province.code == find.province.code);

    print('nationalIdProvince object: $nationalIdProvince');

    return find.copyWith(province: nationalIdProvince);
  }
  return null;
}