feat: Implement agent search functionality and update the home screen to dynamically display professional data.

This commit is contained in:
pradeepkumar
2026-03-07 10:25:53 +05:30
parent 379fbfe0a8
commit aefe80253f
18 changed files with 1655 additions and 627 deletions

View File

@@ -53,12 +53,45 @@ class AgentProfile {
String? get avatarUrl => avatar ?? user?.avatar;
String get location {
// Direct fields first
if (city != null && state != null) return '$city, $state';
if (city != null) return city!;
if (state != null) return state!;
// Fallback: extract from fieldValues (matches web getLocationString)
String? fvCity;
String? fvState;
for (final fv in fieldValues) {
final slug = fv.fieldSlug.toLowerCase();
if (slug == 'city' || slug == 'city_name') {
fvCity = _extractFieldString(fv);
} else if (slug == 'state' || slug == 'state_name') {
fvState = _extractFieldString(fv);
}
}
final parts = [fvCity, fvState].where((s) => s != null && s.isNotEmpty);
if (parts.isNotEmpty) return parts.join(', ');
return '';
}
/// Extract a display string from a field value (handles jsonValue arrays).
static String? _extractFieldString(AgentFieldValue fv) {
if (fv.jsonValue is List && (fv.jsonValue as List).isNotEmpty) {
final val = (fv.jsonValue as List).first;
if (val is String && val.isNotEmpty) {
return val
.split('_')
.map((w) => w.isNotEmpty
? '${w[0].toUpperCase()}${w.substring(1).toLowerCase()}'
: '')
.join(' ');
}
}
if (fv.textValue != null && fv.textValue!.isNotEmpty) return fv.textValue;
return null;
}
/// Get experience from field values
String get experienceText {
for (final fv in fieldValues) {
@@ -66,29 +99,50 @@ class AgentProfile {
fv.fieldName.toLowerCase().contains('experience')) {
if (fv.textValue != null) return fv.textValue!;
if (fv.numberValue != null) {
return '${fv.numberValue!.toInt()}+ years in the real estate industry.';
return '${fv.numberValue!.toInt()}+ years in real estate.';
}
}
}
return '';
}
/// Get specializations from field values
/// Get specializations / expertise from field values.
/// Matches web's getExpertiseTags slugs.
List<String> get specializations {
final tags = <String>[];
const expertiseSlugs = [
'about_me_expertise',
'expertise_areas',
'specializations',
'areas_of_expertise',
'expertise',
'specialization',
'property_type',
'loan_type',
];
for (final fv in fieldValues) {
final slug = fv.fieldSlug.toLowerCase();
if (slug.contains('specialization') ||
slug.contains('property_type') ||
slug.contains('loan_type')) {
if (fv.jsonValue is List) {
return (fv.jsonValue as List).map((e) => e.toString()).toList();
}
if (fv.textValue != null) {
return fv.textValue!.split(',').map((s) => s.trim()).toList();
if (!expertiseSlugs.any((s) => slug.contains(s))) continue;
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 (!tags.contains(display)) tags.add(display);
}
} else if (fv.textValue != null && fv.textValue!.trim().isNotEmpty) {
final display = fv.textValue!.trim();
if (!tags.contains(display)) tags.add(display);
}
}
return [];
return tags;
}
factory AgentProfile.fromJson(Map<String, dynamic> json) {