feat: Enhance agent profile data model with new fields and improved data derivation, and update agent search screen UI and icon.

This commit is contained in:
pradeepkumar
2026-03-07 22:26:08 +05:30
parent ee08e86449
commit 402c1cf206
2 changed files with 86 additions and 25 deletions

View File

@@ -23,6 +23,9 @@ class AgentProfile {
final AgentUser? user;
final List<AgentFieldValue> fieldValues;
final String? createdAt;
final List<String> legacySpecializations;
final List<String> languages;
final List<String> serviceAreas;
const AgentProfile({
required this.id,
@@ -47,6 +50,9 @@ class AgentProfile {
this.user,
this.fieldValues = const [],
this.createdAt,
this.legacySpecializations = const [],
this.languages = const [],
this.serviceAreas = const [],
});
String get fullName => '$firstName $lastName'.trim();
@@ -69,6 +75,16 @@ class AgentProfile {
/// Get avatar URL — check agent avatar first, then user avatar
String? get avatarUrl => avatar ?? user?.avatar;
/// Get description — check fieldValues 'description' first, then bio (matches web)
String get description {
for (final fv in fieldValues) {
if (fv.fieldSlug == 'description' && fv.textValue != null && fv.textValue!.isNotEmpty) {
return fv.textValue!;
}
}
return bio ?? '';
}
String get location {
// Direct fields first
if (city != null && state != null) return '$city, $state';
@@ -89,6 +105,9 @@ class AgentProfile {
final parts = [fvCity, fvState].where((s) => s != null && s.isNotEmpty);
if (parts.isNotEmpty) return parts.join(', ');
if (country != null && country!.isNotEmpty) return country!;
if (serviceAreas.isNotEmpty) return serviceAreas.first;
return '';
}
@@ -159,6 +178,17 @@ class AgentProfile {
if (!tags.contains(display)) tags.add(display);
}
}
// Add from legacy specializations array
for (final spec in legacySpecializations) {
if (spec.isNotEmpty && !tags.contains(spec)) tags.add(spec);
}
// Add from languages array
for (final lang in languages) {
if (lang.isNotEmpty && !tags.contains(lang)) tags.add(lang);
}
return tags;
}
@@ -193,6 +223,18 @@ class AgentProfile {
.toList() ??
const [],
createdAt: json['createdAt'] as String?,
legacySpecializations: (json['specializations'] as List<dynamic>?)
?.map((e) => e.toString())
.toList() ??
const [],
languages: (json['languages'] as List<dynamic>?)
?.map((e) => e.toString())
.toList() ??
const [],
serviceAreas: (json['serviceAreas'] as List<dynamic>?)
?.map((e) => e.toString())
.toList() ??
const [],
);
}
}
@@ -241,11 +283,14 @@ class AgentFieldValue {
});
factory AgentFieldValue.fromJson(Map<String, dynamic> json) {
// API returns field info nested: { field: { slug, name, fieldType } }
// Fallback to top-level fieldSlug/fieldName/fieldType for compatibility
final field = json['field'] as Map<String, dynamic>?;
return AgentFieldValue(
id: json['id'] as String? ?? '',
fieldSlug: json['fieldSlug'] as String? ?? '',
fieldName: json['fieldName'] as String? ?? '',
fieldType: json['fieldType'] as String? ?? '',
fieldSlug: field?['slug'] as String? ?? json['fieldSlug'] as String? ?? '',
fieldName: field?['name'] as String? ?? json['fieldName'] as String? ?? '',
fieldType: field?['fieldType'] as String? ?? json['fieldType'] as String? ?? '',
textValue: json['textValue'] as String?,
numberValue: json['numberValue'] as num?,
booleanValue: json['booleanValue'] as bool?,