refactor: strip state prefixes from city names in agent location display
This commit is contained in:
@@ -184,8 +184,10 @@ class AgentDetailState {
|
||||
if (fvStates != null) parts.addAll(fvStates.map(_normalizeStateCode));
|
||||
if (fvCities != null) {
|
||||
for (final c in fvCities) {
|
||||
if (!parts.any((p) => p.toLowerCase() == c.toLowerCase())) {
|
||||
parts.add(c);
|
||||
// City values carry a state prefix (e.g. "ne_adams"); strip it for display.
|
||||
final cleaned = _stripCityStatePrefix(c);
|
||||
if (!parts.any((p) => p.toLowerCase() == cleaned.toLowerCase())) {
|
||||
parts.add(cleaned);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,7 +198,7 @@ class AgentDetailState {
|
||||
parts.add(_normalizeStateCode(agent!.state!));
|
||||
}
|
||||
if (agent!.city != null && agent!.city!.isNotEmpty) {
|
||||
parts.add(agent!.city!);
|
||||
parts.add(_stripCityStatePrefix(agent!.city!));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +220,23 @@ class AgentDetailState {
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
/// Strip the state-code prefix from a city value (e.g. "Ne Adams" / "ne_adams" → "Adams").
|
||||
/// After removing the prefix, title-case the remainder.
|
||||
String _stripCityStatePrefix(String raw) {
|
||||
final trimmed = raw.trim();
|
||||
// Snake-case with a 2-letter state prefix: ne_adams, co_aetna_estates
|
||||
final snakeMatch = RegExp(r'^[a-z]{2}_', caseSensitive: false).firstMatch(trimmed);
|
||||
if (snakeMatch != null) {
|
||||
return titleCase(trimmed.substring(snakeMatch.end));
|
||||
}
|
||||
// Title-cased with a 2-letter prefix token: "Ne Adams", "Co Aetna Estates"
|
||||
final spaceMatch = RegExp(r'^[A-Za-z]{2}\s+').firstMatch(trimmed);
|
||||
if (spaceMatch != null) {
|
||||
return trimmed.substring(spaceMatch.end);
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
/// Combined location text for single-line display.
|
||||
String get locationText {
|
||||
final parts = locationParts;
|
||||
|
||||
Reference in New Issue
Block a user