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

@@ -2,75 +2,28 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:go_router/go_router.dart';
import 'package:real_estate_mobile/config/app_config.dart';
import 'package:real_estate_mobile/core/constants/app_colors.dart';
import 'package:real_estate_mobile/features/agents/data/models/agent_profile.dart';
import 'package:real_estate_mobile/features/agents/presentation/providers/agents_provider.dart';
import 'package:real_estate_mobile/features/home/data/models/landing_page_content.dart';
import 'package:real_estate_mobile/features/home/presentation/providers/home_provider.dart';
/// Local fallback images for professionals when CMS returns no image.
/// Local fallback images for professionals when API returns no avatar.
const _fallbackImages = [
'assets/images/professional-1.jpg',
'assets/images/professional-2.jpg',
'assets/images/professional-3.jpg',
];
/// Default agents data — matches web's hardcoded agentsData fallback.
const _defaultAgents = [
ProfessionalItem(
name: 'Arjun Mehta',
subtitle: 'Residential Property Expert',
location: 'San Francisco, CA',
experience: '10+ years in the real estate industry.',
expertise: ['Residential', 'Rental', 'Commercial', 'Inspection', 'Land', 'Rental'],
),
ProfessionalItem(
name: 'Anderson',
subtitle: 'Rental & Investment Consultant',
location: 'New York',
experience: '7+ years in the real estate industry.',
expertise: ['Residential', 'Rental', 'Commercial'],
),
ProfessionalItem(
name: 'Sarah Johnson',
subtitle: 'Luxury Real Estate Specialist',
location: 'Los Angeles, CA',
experience: '12+ years in the real estate industry.',
expertise: ['Luxury', 'Residential', 'Investment'],
),
];
/// Default lenders data — matches web's hardcoded lendersData fallback.
const _defaultLenders = [
ProfessionalItem(
name: 'Sarah Johnson',
subtitle: 'Mortgage Specialist',
location: 'Los Angeles, CA',
experience: '10+ years in mortgage lending.',
expertise: ['FHA Loans', 'Conventional', 'VA Loans', 'Refinancing', 'Jumbo'],
),
ProfessionalItem(
name: 'Michael Chen',
subtitle: 'Senior Loan Officer',
location: 'Seattle, WA',
experience: '7+ years in lending.',
expertise: ['Jumbo Loans', 'Refinancing', 'Investment', 'First-time', 'USDA'],
),
ProfessionalItem(
name: 'Emily Davis',
subtitle: 'Home Loan Advisor',
location: 'Austin, TX',
experience: '5+ years in mortgage industry.',
expertise: ['First-time Buyers', 'FHA', 'USDA Loans', 'VA Loans', 'Conventional'],
),
];
/// Default content — matches web's defaultContent pattern.
const _defaultContent = TopProfessionalsContent(
/// Default CMS content for title/CTA text only.
const _defaultCmsContent = TopProfessionalsContent(
title: '"Meet top real estate professionals"',
ctaText: 'Discover 5,000+ Top Real Estate Agents in Our Network.',
ctaButtonText: 'See All Agents',
agents: _defaultAgents,
lenders: _defaultLenders,
agents: [],
lenders: [],
);
class TopProfessionalsSection extends ConsumerStatefulWidget {
@@ -83,37 +36,51 @@ class TopProfessionalsSection extends ConsumerStatefulWidget {
class _TopProfessionalsSectionState
extends ConsumerState<TopProfessionalsSection> {
String _activeTab = 'agents';
int _currentPage = 0;
late PageController _pageController;
late ScrollController _scrollController;
@override
void initState() {
super.initState();
_pageController = PageController();
_scrollController = ScrollController();
_scrollController.addListener(_onScroll);
}
@override
void dispose() {
_pageController.dispose();
_scrollController.removeListener(_onScroll);
_scrollController.dispose();
super.dispose();
}
void _onScroll() {
if (!_scrollController.hasClients) return;
final cardWidth = MediaQuery.of(context).size.width - 48;
if (cardWidth <= 0) return;
final page = (_scrollController.offset / cardWidth).round();
if (page != _currentPage) {
setState(() => _currentPage = page);
}
}
@override
Widget build(BuildContext context) {
// CMS data for title/CTA text only
final homeState = ref.watch(homeProvider);
final cmsContent = homeState.content?.topProfessionals ?? _defaultCmsContent;
// Use CMS data if available, otherwise fallback to defaults (same as web)
final data = homeState.content?.topProfessionals ?? _defaultContent;
final activeList = _activeTab == 'agents' ? data.agents : data.lenders;
// Real agent data from GET /agents API (like web does)
final topProState = ref.watch(topProfessionalsProvider);
final activeList = topProState.activeList;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column(
children: [
Text(
data.title,
cmsContent.title.isNotEmpty
? cmsContent.title
: _defaultCmsContent.title,
textAlign: TextAlign.center,
style: const TextStyle(
fontFamily: 'Fractul',
@@ -125,33 +92,42 @@ class _TopProfessionalsSectionState
const SizedBox(height: 24),
// Agents / Lenders Tab
_buildCategoryTab(),
_buildCategoryTab(topProState.activeTab),
const SizedBox(height: 24),
// Content
if (homeState.isLoading)
if (topProState.isLoading)
const Padding(
padding: EdgeInsets.symmetric(vertical: 40),
child: CircularProgressIndicator(
color: AppColors.accentOrange,
),
)
else if (homeState.error != null)
_buildErrorState(homeState.error!)
else if (topProState.error != null)
_buildErrorState(topProState.error!)
else if (activeList.isEmpty)
_buildEmptyState()
_buildEmptyState(topProState.activeTab)
else ...[
// Professional Cards - horizontal scroll
SizedBox(
height: 500,
child: PageView.builder(
controller: _pageController,
height: 480,
child: ListView.builder(
controller: _scrollController,
scrollDirection: Axis.horizontal,
physics: const BouncingScrollPhysics(),
itemCount: activeList.length,
onPageChanged: (index) {
setState(() => _currentPage = index);
},
itemBuilder: (context, index) {
return _buildProfessionalCard(activeList[index], index: index);
final cardWidth = MediaQuery.of(context).size.width - 48;
return SizedBox(
width: cardWidth,
child: Padding(
padding: EdgeInsets.only(
left: index == 0 ? 0 : 8,
right: index == activeList.length - 1 ? 0 : 8,
),
child: _buildProfessionalCard(activeList[index], index: index),
),
);
},
),
),
@@ -163,13 +139,13 @@ class _TopProfessionalsSectionState
const SizedBox(height: 32),
// See All Agents CTA
_buildSeeAllAgentsCta(data),
_buildSeeAllAgentsCta(cmsContent),
],
),
);
}
Widget _buildCategoryTab() {
Widget _buildCategoryTab(String activeTab) {
return Container(
height: 45,
decoration: BoxDecoration(
@@ -182,18 +158,16 @@ class _TopProfessionalsSectionState
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
_activeTab = 'agents';
_currentPage = 0;
});
if (_pageController.hasClients) {
_pageController.jumpToPage(0);
ref.read(topProfessionalsProvider.notifier).setActiveTab('agents');
setState(() => _currentPage = 0);
if (_scrollController.hasClients) {
_scrollController.jumpTo(0);
}
},
child: Container(
padding: const EdgeInsets.symmetric(vertical: 12),
decoration: BoxDecoration(
color: _activeTab == 'agents'
color: activeTab == 'agents'
? AppColors.accentOrange
: Colors.transparent,
borderRadius: BorderRadius.circular(15),
@@ -206,14 +180,14 @@ class _TopProfessionalsSectionState
width: 24,
height: 24,
colorFilter: ColorFilter.mode(
_activeTab == 'agents'
activeTab == 'agents'
? Colors.white
: AppColors.primaryDark,
BlendMode.srcIn,
),
placeholderBuilder: (_) => Icon(
Icons.people,
color: _activeTab == 'agents'
color: activeTab == 'agents'
? Colors.white
: AppColors.primaryDark,
size: 24,
@@ -226,7 +200,7 @@ class _TopProfessionalsSectionState
fontFamily: 'SourceSerif4',
fontSize: 17,
fontWeight: FontWeight.w600,
color: _activeTab == 'agents'
color: activeTab == 'agents'
? Colors.white
: AppColors.primaryDark,
),
@@ -240,18 +214,16 @@ class _TopProfessionalsSectionState
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
_activeTab = 'lenders';
_currentPage = 0;
});
if (_pageController.hasClients) {
_pageController.jumpToPage(0);
ref.read(topProfessionalsProvider.notifier).setActiveTab('lenders');
setState(() => _currentPage = 0);
if (_scrollController.hasClients) {
_scrollController.jumpTo(0);
}
},
child: Container(
padding: const EdgeInsets.symmetric(vertical: 12),
decoration: BoxDecoration(
color: _activeTab == 'lenders'
color: activeTab == 'lenders'
? AppColors.accentOrange
: Colors.transparent,
borderRadius: BorderRadius.circular(15),
@@ -264,14 +236,14 @@ class _TopProfessionalsSectionState
width: 24,
height: 24,
colorFilter: ColorFilter.mode(
_activeTab == 'lenders'
activeTab == 'lenders'
? Colors.white
: AppColors.primaryDark,
BlendMode.srcIn,
),
placeholderBuilder: (_) => Icon(
Icons.calendar_today,
color: _activeTab == 'lenders'
color: activeTab == 'lenders'
? Colors.white
: AppColors.primaryDark,
size: 24,
@@ -284,7 +256,7 @@ class _TopProfessionalsSectionState
fontFamily: 'SourceSerif4',
fontSize: 17,
fontWeight: FontWeight.w600,
color: _activeTab == 'lenders'
color: activeTab == 'lenders'
? Colors.white
: AppColors.primaryDark,
),
@@ -299,9 +271,9 @@ class _TopProfessionalsSectionState
);
}
/// Resolves an image URL: full URL → use as-is, relative prepend base URL.
String? _resolveImageUrl(String imageUrl) {
if (imageUrl.isEmpty) return null;
/// Resolves an image URL: full URL as-is, relative prepend base URL.
String? _resolveImageUrl(String? imageUrl) {
if (imageUrl == null || imageUrl.isEmpty) return null;
if (imageUrl.startsWith('http://') || imageUrl.startsWith('https://')) {
return imageUrl;
}
@@ -312,9 +284,9 @@ class _TopProfessionalsSectionState
return null;
}
/// Builds the card image: CachedNetworkImage for valid URLs, local asset fallback otherwise.
Widget _buildCardImage(ProfessionalItem professional, int index) {
final resolvedUrl = _resolveImageUrl(professional.imageUrl);
/// Builds the card image from AgentProfile avatar.
Widget _buildCardImage(AgentProfile agent, int index) {
final resolvedUrl = _resolveImageUrl(agent.avatarUrl);
if (resolvedUrl != null) {
return CachedNetworkImage(
@@ -329,7 +301,6 @@ class _TopProfessionalsSectionState
return _buildImagePlaceholder(index);
}
/// Shows a local fallback professional image (cycles through 3 images).
Widget _buildImagePlaceholder(int index) {
final assetPath = _fallbackImages[index % _fallbackImages.length];
return Image.asset(
@@ -341,8 +312,13 @@ class _TopProfessionalsSectionState
);
}
// ── Unified Professional Card (matches Figma design for both tabs) ──
Widget _buildProfessionalCard(ProfessionalItem professional, {int index = 0}) {
// -- Professional Card using real AgentProfile data --
Widget _buildProfessionalCard(AgentProfile agent, {int index = 0}) {
final rating = agent.averageRating ?? 0.0;
final expertise = agent.specializations;
final experience = agent.experienceText;
final subtitle = agent.agentType?.name ?? agent.headline ?? '';
return Container(
decoration: BoxDecoration(
color: Colors.white,
@@ -351,237 +327,176 @@ class _TopProfessionalsSectionState
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
// Image
ClipRRect(
borderRadius:
const BorderRadius.vertical(top: Radius.circular(15)),
child: _buildCardImage(professional, index),
child: _buildCardImage(agent, index),
),
// Content
Expanded(
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Row 1: Name + verified badge + star Rating
Row(
children: [
Expanded(
child: Row(
children: [
Flexible(
child: Text(
professional.name,
style: const TextStyle(
fontFamily: 'Fractul',
fontSize: 14,
fontWeight: FontWeight.w700,
color: AppColors.primaryDark,
),
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 6),
SvgPicture.asset(
'assets/icons/verified_badge_icon.svg',
width: 16,
height: 16,
placeholderBuilder: (_) => const Icon(
Icons.verified,
color: Color(0xFF1DA1F2),
size: 16,
),
),
],
),
),
SvgPicture.asset(
'assets/icons/star_rating_icon.svg',
width: 16,
height: 16,
placeholderBuilder: (_) => const Icon(
Icons.star,
color: Color(0xFFFFDE21),
size: 16,
),
),
const SizedBox(width: 4),
const Text(
'Rating',
style: TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
),
),
],
Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Row 1: Name only (matches Figma 49:6310)
Text(
agent.fullName,
style: const TextStyle(
fontFamily: 'Fractul',
fontSize: 14,
fontWeight: FontWeight.w700,
color: AppColors.primaryDark,
),
const SizedBox(height: 4),
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
// Row 2: (Subtitle) in parentheses
if (professional.subtitle.isNotEmpty)
Text(
'(${professional.subtitle})',
style: const TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 10,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
// Row 2: Subtitle/headline
if (subtitle.isNotEmpty)
Text(
'($subtitle)',
style: const TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 10,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
),
const SizedBox(height: 4),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
// Row 3: Verified badge + "Verified local agent" in green
// Row 3: Verified badge + "Verified local agent" in green (Figma 49:6319)
if (agent.isVerified)
Row(
children: [
SvgPicture.asset(
'assets/icons/verified_badge_icon.svg',
width: 14,
height: 14,
width: 16,
height: 16,
placeholderBuilder: (_) => const Icon(
Icons.verified,
color: Color(0xFF638559),
size: 14,
size: 16,
),
),
const SizedBox(width: 4),
const SizedBox(width: 6),
const Text(
'"Verified local agent"',
'\u201CVerified local agent\u201D',
style: TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 10,
fontWeight: FontWeight.w400,
fontSize: 14,
fontWeight: FontWeight.w500,
color: Color(0xFF638559),
),
),
],
),
const SizedBox(height: 8),
const SizedBox(height: 8),
// Row 4: Location: label
if (professional.location.isNotEmpty) ...[
const Text(
'Location:',
style: TextStyle(
fontFamily: 'Fractul',
fontSize: 14,
fontWeight: FontWeight.w700,
color: AppColors.primaryDark,
),
// Row 4: Location
if (agent.location.isNotEmpty) ...[
const Text(
'Location:',
style: TextStyle(
fontFamily: 'Fractul',
fontSize: 14,
fontWeight: FontWeight.w700,
color: AppColors.primaryDark,
),
const SizedBox(height: 2),
// Pin icon + location text
Row(
),
const SizedBox(height: 2),
Row(
children: [
SvgPicture.asset(
'assets/icons/location_pin_icon.svg',
width: 14,
height: 14,
placeholderBuilder: (_) => const Icon(
Icons.location_on,
color: AppColors.accentOrange,
size: 14,
),
),
const SizedBox(width: 4),
Expanded(
child: Text(
agent.location,
style: const TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 10,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
),
overflow: TextOverflow.ellipsis,
),
),
],
),
const SizedBox(height: 8),
],
// Row 5: Expertise tags
if (expertise.isNotEmpty) ...[
const Text(
'Expertise:',
style: TextStyle(
fontFamily: 'Fractul',
fontSize: 14,
fontWeight: FontWeight.w700,
color: AppColors.primaryDark,
),
),
const SizedBox(height: 6),
Wrap(
spacing: 8,
runSpacing: 6,
children: expertise
.take(6)
.map((tag) => _buildTag(tag))
.toList(),
),
const SizedBox(height: 12),
],
// Experience text
if (experience.isNotEmpty) ...[
RichText(
text: TextSpan(
children: [
SvgPicture.asset(
'assets/icons/location_pin_icon.svg',
width: 14,
height: 14,
placeholderBuilder: (_) => const Icon(
Icons.location_on,
color: AppColors.accentOrange,
size: 14,
const TextSpan(
text: 'Experience: ',
style: TextStyle(
fontFamily: 'Fractul',
fontSize: 14,
fontWeight: FontWeight.w700,
color: AppColors.primaryDark,
),
),
const SizedBox(width: 4),
Expanded(
child: Text(
professional.location,
style: const TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 10,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
),
overflow: TextOverflow.ellipsis,
TextSpan(
text: experience,
style: const TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
),
),
],
),
const SizedBox(height: 8),
],
// Row 5: Expertise: label + tags
if (professional.expertise.isNotEmpty) ...[
const Text(
'Expertise:',
style: TextStyle(
fontFamily: 'Fractul',
fontSize: 14,
fontWeight: FontWeight.w700,
color: AppColors.primaryDark,
),
),
const SizedBox(height: 6),
// Tags as bordered pills
Wrap(
spacing: 8,
runSpacing: 6,
children: professional.expertise
.take(6)
.map((tag) => _buildTag(tag))
.toList(),
),
],
const Spacer(),
// Experience text
if (professional.experience.isNotEmpty)
RichText(
text: TextSpan(
children: [
const TextSpan(
text: 'Experience: ',
style: TextStyle(
fontFamily: 'Fractul',
fontSize: 14,
fontWeight: FontWeight.w700,
color: AppColors.primaryDark,
),
),
TextSpan(
text: professional.experience,
style: const TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
),
),
],
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 8),
// 5 star rating icons row at bottom
Row(
children: List.generate(
5,
(index) => Padding(
padding: const EdgeInsets.only(right: 4),
child: SvgPicture.asset(
'assets/icons/star_rating_icon.svg',
width: 18,
height: 18,
placeholderBuilder: (_) => const Icon(
Icons.star,
color: Color(0xFFFFDE21),
size: 18,
),
),
),
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 8),
],
),
// Star rating row at bottom
_buildStarRating(rating),
],
),
),
],
@@ -589,6 +504,49 @@ class _TopProfessionalsSectionState
);
}
Widget _buildStarRating(double rating) {
final fullStars = rating.floor();
final hasHalfStar = (rating - fullStars) >= 0.3;
return Row(
children: List.generate(5, (index) {
if (index < fullStars) {
return Padding(
padding: const EdgeInsets.only(right: 4),
child: SvgPicture.asset(
'assets/icons/star_rating_icon.svg',
width: 18,
height: 18,
placeholderBuilder: (_) => const Icon(
Icons.star,
color: Color(0xFFFFDE21),
size: 18,
),
),
);
} else if (index == fullStars && hasHalfStar) {
return const Padding(
padding: EdgeInsets.only(right: 4),
child: Icon(
Icons.star_half,
color: Color(0xFFFFDE21),
size: 18,
),
);
} else {
return const Padding(
padding: EdgeInsets.only(right: 4),
child: Icon(
Icons.star_border,
color: Color(0xFFFFDE21),
size: 18,
),
);
}
}),
);
}
Widget _buildAvatarPlaceholder() {
return Container(
width: double.infinity,
@@ -675,7 +633,8 @@ class _TopProfessionalsSectionState
),
const SizedBox(height: 16),
TextButton(
onPressed: () => ref.read(homeProvider.notifier).loadContent(),
onPressed: () =>
ref.read(topProfessionalsProvider.notifier).refresh(),
child: const Text(
'Retry',
style: TextStyle(
@@ -691,13 +650,13 @@ class _TopProfessionalsSectionState
);
}
Widget _buildEmptyState() {
Widget _buildEmptyState(String activeTab) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 40),
child: Column(
children: [
Icon(
_activeTab == 'agents'
activeTab == 'agents'
? Icons.people_outline
: Icons.account_balance_outlined,
color: AppColors.hintText,
@@ -705,7 +664,7 @@ class _TopProfessionalsSectionState
),
const SizedBox(height: 12),
Text(
'No ${_activeTab == 'agents' ? 'agents' : 'lenders'} found',
'No ${activeTab == 'agents' ? 'agents' : 'lenders'} found',
style: const TextStyle(
fontFamily: 'Fractul',
fontSize: 14,
@@ -719,6 +678,13 @@ class _TopProfessionalsSectionState
}
Widget _buildSeeAllAgentsCta(TopProfessionalsContent content) {
final ctaText = content.ctaText.isNotEmpty
? content.ctaText
: _defaultCmsContent.ctaText;
final ctaButtonText = content.ctaButtonText.isNotEmpty
? content.ctaButtonText
: _defaultCmsContent.ctaButtonText;
return Container(
width: double.infinity,
padding: const EdgeInsets.all(24),
@@ -752,7 +718,7 @@ class _TopProfessionalsSectionState
),
const SizedBox(height: 12),
Text(
content.ctaText,
ctaText,
textAlign: TextAlign.center,
style: const TextStyle(
fontFamily: 'SourceSerif4',
@@ -765,17 +731,17 @@ class _TopProfessionalsSectionState
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () {},
onPressed: () => context.push('/agents/search'),
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.primaryDark,
foregroundColor: Colors.white,
backgroundColor: AppColors.accentOrange,
foregroundColor: AppColors.primaryDark,
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
child: Text(
content.ctaButtonText,
ctaButtonText,
style: const TextStyle(
fontFamily: 'Fractul',
fontSize: 16,