refactor: normalize location display by stripping state prefixes from cities and uppercasing state codes
This commit is contained in:
@@ -594,23 +594,41 @@ class _AgentCardState extends State<_AgentCard> {
|
||||
const SizedBox(width: 4),
|
||||
Builder(builder: (_) {
|
||||
final allParts = <String>[];
|
||||
// Extract states first, then cities (state-first display)
|
||||
List<String> extractValues(dynamic fv) {
|
||||
// Format raw slug/label. For cities, strip 2-letter
|
||||
// state prefix ("nd_hurley" → "Hurley"). For states,
|
||||
// uppercase 2-letter codes ("nd" → "ND"). Matches
|
||||
// web's stripCityPrefix + extractAllValues.
|
||||
String formatPart(String raw, {required bool isCity}) {
|
||||
var s = raw.trim();
|
||||
if (isCity) {
|
||||
s = s.replaceFirst(
|
||||
RegExp(r'^[a-z]{2}_', caseSensitive: false), '');
|
||||
}
|
||||
final titled = s
|
||||
.split('_')
|
||||
.map((w) => w.isNotEmpty
|
||||
? '${w[0].toUpperCase()}${w.substring(1).toLowerCase()}'
|
||||
: '')
|
||||
.join(' ');
|
||||
if (!isCity && titled.length == 2) {
|
||||
return titled.toUpperCase();
|
||||
}
|
||||
return titled;
|
||||
}
|
||||
|
||||
List<String> extractValues(dynamic fv,
|
||||
{required bool isCity}) {
|
||||
final out = <String>[];
|
||||
if (fv.jsonValue is List) {
|
||||
for (final v in (fv.jsonValue as List)) {
|
||||
final s = v.toString().trim();
|
||||
if (s.isEmpty) continue;
|
||||
out.add(s
|
||||
.split('_')
|
||||
.map((w) => w.isNotEmpty
|
||||
? '${w[0].toUpperCase()}${w.substring(1).toLowerCase()}'
|
||||
: '')
|
||||
.join(' '));
|
||||
out.add(formatPart(s, isCity: isCity));
|
||||
}
|
||||
} else if (fv.textValue != null &&
|
||||
(fv.textValue as String).isNotEmpty) {
|
||||
out.add(fv.textValue as String);
|
||||
out.add(formatPart(fv.textValue as String,
|
||||
isCity: isCity));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -626,7 +644,7 @@ class _AgentCardState extends State<_AgentCard> {
|
||||
for (final fv in agent.fieldValues) {
|
||||
final slug = fv.fieldSlug.toLowerCase();
|
||||
if (slug == 'state' || slug == 'state_name') {
|
||||
for (final v in extractValues(fv)) {
|
||||
for (final v in extractValues(fv, isCity: false)) {
|
||||
addUnique(v);
|
||||
}
|
||||
}
|
||||
@@ -635,7 +653,7 @@ class _AgentCardState extends State<_AgentCard> {
|
||||
for (final fv in agent.fieldValues) {
|
||||
final slug = fv.fieldSlug.toLowerCase();
|
||||
if (slug == 'city' || slug == 'city_name') {
|
||||
for (final v in extractValues(fv)) {
|
||||
for (final v in extractValues(fv, isCity: true)) {
|
||||
addUnique(v);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user