RegionFeature constructor

RegionFeature({
  1. String? id,
  2. String? iso1A2,
  3. String? iso1A3,
  4. String? iso1N3,
  5. String? m49,
  6. required String wikidata,
  7. String? emojiFlag,
  8. String? ccTLD,
  9. required String nameEn,
  10. List<String>? aliases,
  11. String? country,
  12. List<String>? groups,
  13. List<String>? members,
  14. RegionLevel? level,
  15. RegionIsoStatus? isoStatus,
  16. RegionDrivingSide? driveSide,
  17. RegionSpeedUnit? roadSpeedUnit,
  18. RegionHeightUnit? roadHeightUnit,
  19. List<String>? callingCodes,
  20. bool hasGeometry = true,
})

Implementation

RegionFeature({
  String? id,
  this.iso1A2,
  this.iso1A3,
  this.iso1N3,
  this.m49,
  required this.wikidata,
  this.emojiFlag,
  this.ccTLD,
  required this.nameEn,
  List<String>? aliases,
  this.country,
  List<String>? groups,
  List<String>? members,
  RegionLevel? level,
  this.isoStatus,
  this.driveSide,
  this.roadSpeedUnit,
  this.roadHeightUnit,
  List<String>? callingCodes,
  this.hasGeometry = true,
}) : id = id ?? iso1A2 ?? m49 ?? wikidata {
  this.aliases = aliases ?? [];
  this.groups = groups ?? [];
  this.members = members ?? [];
  this.callingCodes = callingCodes ?? [];

  if (m49 == null && iso1N3 != null) {
    // M49 is a superset of ISO numerics so we only need to store one
    m49 = iso1N3;
  }

  if (level != RegionLevel.unitedNations) {
    if (ccTLD == null && iso1A2 != null) {
      // ccTLD is nearly the same as iso1A2, so we only need to explicitly code any exceptions
      ccTLD = '.${iso1A2!.toLowerCase()}';
    }
  }

  if (level == null) {
    if (country == null) {
      level = RegionLevel.country;
    } else if (iso1A2 == null || isoStatus == RegionIsoStatus.official) {
      level = RegionLevel.territory;
    } else {
      level = RegionLevel.subterritory;
    }
  }
  this.level = level;

  if (country != null && hasGeometry) {
    this.groups.add(country!);
  }
  if (m49 != '001') {
    this.groups.add('001');
  }

  if (iso1A2 != null) {
    // Calculates the emoji flag sequence from the alpha-2 code (if any) and caches it
    emojiFlag = String.fromCharCodes(iso1A2!.codeUnits.map((e) => e + 127397));
  }
}