From 1ef02383a6a10c10f097ad27be67d03dbefa8a13 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Sat, 11 Apr 2026 22:52:13 +0530 Subject: [PATCH] refactor: update agent location display logic to prioritize state over city across UI and models --- .../agents/data/models/agent_profile.dart | 8 +-- .../providers/agent_detail_provider.dart | 21 ++++--- .../screens/agent_search_screen.dart | 62 ++++++++++++------- .../presentation/screens/login_screen.dart | 2 +- 4 files changed, 57 insertions(+), 36 deletions(-) diff --git a/lib/features/agents/data/models/agent_profile.dart b/lib/features/agents/data/models/agent_profile.dart index 4a497f0..11fea66 100644 --- a/lib/features/agents/data/models/agent_profile.dart +++ b/lib/features/agents/data/models/agent_profile.dart @@ -96,10 +96,10 @@ class AgentProfile { } String get location { - // Direct fields first - if (city != null && state != null) return '$city, $state'; - if (city != null) return city!; + // Direct fields first (state first, then city) + if (city != null && state != null) return '$state, $city'; if (state != null) return state!; + if (city != null) return city!; // Fallback: extract from fieldValues (matches web getLocationString) String? fvCity; @@ -112,7 +112,7 @@ class AgentProfile { fvState = _extractFieldString(fv); } } - final parts = [fvCity, fvState].where((s) => s != null && s.isNotEmpty); + final parts = [fvState, fvCity].where((s) => s != null && s.isNotEmpty); if (parts.isNotEmpty) return parts.join(', '); if (country != null && country!.isNotEmpty) return country!; diff --git a/lib/features/agents/presentation/providers/agent_detail_provider.dart b/lib/features/agents/presentation/providers/agent_detail_provider.dart index ceaaaba..6a4c3a7 100644 --- a/lib/features/agents/presentation/providers/agent_detail_provider.dart +++ b/lib/features/agents/presentation/providers/agent_detail_provider.dart @@ -165,7 +165,8 @@ class AgentDetailState { // ── Location (from fieldValues, matching web profileDataMapper) ── /// All location parts as individual items (for "+N more" display). - /// Sources: detail fieldValues city/state arrays → agent model → serviceAreas + /// Sources: detail fieldValues state/city arrays → agent model → serviceAreas + /// Order: state first, then city. List get locationParts { final parts = []; @@ -180,23 +181,23 @@ class AgentDetailState { fvStates = _extractAllValuesAsList(fv); } } - if (fvCities != null) parts.addAll(fvCities); - if (fvStates != null) { - for (final s in fvStates) { - if (!parts.any((p) => p.toLowerCase() == s.toLowerCase())) { - parts.add(s); + if (fvStates != null) parts.addAll(fvStates); + if (fvCities != null) { + for (final c in fvCities) { + if (!parts.any((p) => p.toLowerCase() == c.toLowerCase())) { + parts.add(c); } } } - // 2. Fallback: agent model direct city/state + // 2. Fallback: agent model direct state/city if (parts.isEmpty && agent != null) { - if (agent!.city != null && agent!.city!.isNotEmpty) { - parts.add(agent!.city!); - } if (agent!.state != null && agent!.state!.isNotEmpty) { parts.add(agent!.state!); } + if (agent!.city != null && agent!.city!.isNotEmpty) { + parts.add(agent!.city!); + } } // 3. Fallback: serviceAreas diff --git a/lib/features/agents/presentation/screens/agent_search_screen.dart b/lib/features/agents/presentation/screens/agent_search_screen.dart index 954b1e7..a78839b 100644 --- a/lib/features/agents/presentation/screens/agent_search_screen.dart +++ b/lib/features/agents/presentation/screens/agent_search_screen.dart @@ -594,29 +594,49 @@ class _AgentCardState extends State<_AgentCard> { const SizedBox(width: 4), Builder(builder: (_) { final allParts = []; - // Extract all cities/states from fieldValues arrays + // Extract states first, then cities (state-first display) + List extractValues(dynamic fv) { + final out = []; + 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(' ')); + } + } else if (fv.textValue != null && + (fv.textValue as String).isNotEmpty) { + out.add(fv.textValue as String); + } + return out; + } + + void addUnique(String value) { + if (!allParts.any((p) => + p.toLowerCase() == value.toLowerCase())) { + allParts.add(value); + } + } + + // 1. States first for (final fv in agent.fieldValues) { final slug = fv.fieldSlug.toLowerCase(); - if (slug == 'city' || slug == 'city_name' || - slug == 'state' || slug == 'state_name') { - if (fv.jsonValue is List) { - for (final v in (fv.jsonValue as List)) { - final s = v.toString().trim(); - if (s.isEmpty) continue; - final display = s - .split('_') - .map((w) => w.isNotEmpty - ? '${w[0].toUpperCase()}${w.substring(1).toLowerCase()}' - : '') - .join(' '); - if (!allParts.any((p) => - p.toLowerCase() == display.toLowerCase())) { - allParts.add(display); - } - } - } else if (fv.textValue != null && - fv.textValue!.isNotEmpty) { - allParts.add(fv.textValue!); + if (slug == 'state' || slug == 'state_name') { + for (final v in extractValues(fv)) { + addUnique(v); + } + } + } + // 2. Cities next + for (final fv in agent.fieldValues) { + final slug = fv.fieldSlug.toLowerCase(); + if (slug == 'city' || slug == 'city_name') { + for (final v in extractValues(fv)) { + addUnique(v); } } } diff --git a/lib/features/auth/presentation/screens/login_screen.dart b/lib/features/auth/presentation/screens/login_screen.dart index 4506e4f..7ddafae 100644 --- a/lib/features/auth/presentation/screens/login_screen.dart +++ b/lib/features/auth/presentation/screens/login_screen.dart @@ -121,7 +121,7 @@ class _LoginScreenState extends ConsumerState { const Padding( padding: EdgeInsets.symmetric(horizontal: 16), child: Text( - 'Login or create an account to enjoy FREE consultation on all property inquiries.', + 'Login or create an account', textAlign: TextAlign.center, style: TextStyle( fontFamily: 'SourceSerif4',