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

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:go_router/go_router.dart';
import 'package:real_estate_mobile/core/constants/app_colors.dart';
import 'package:real_estate_mobile/features/home/presentation/widgets/featured_professionals_section.dart';
import 'package:real_estate_mobile/features/home/presentation/widgets/features_section.dart';
@@ -143,6 +144,10 @@ class _HomeScreenState extends State<HomeScreen> {
return GestureDetector(
onTap: () {
if (index == 1) {
context.push('/agents/search');
return;
}
setState(() => _selectedIndex = index);
},
behavior: HitTestBehavior.opaque,

View File

@@ -4,8 +4,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.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/home/data/models/landing_page_content.dart';
import 'package:real_estate_mobile/features/home/presentation/providers/home_provider.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';
/// Local fallback images for professionals.
const _fallbackImages = [
@@ -14,39 +14,9 @@ const _fallbackImages = [
'assets/images/professional-3.jpg',
];
/// Default agent data — matches web's hardcoded agentsData fallback.
/// Used when CMS returns no data from admin.
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'],
),
];
/// Featured professionals carousel shown above the agents/lenders tab section.
/// Matches Figma node 49:6248 — compact card with image, name, subtitle,
/// verified+rating row, location, and experience.
///
/// Data flow (same as web pattern):
/// CMS admin → GET /cms/page/landing → topProfessionals.agents
/// Fallback → _defaultAgents (hardcoded, like web's agentsData)
/// Now fetches REAL agent data from GET /agents API (like web does)
/// instead of using CMS/hardcoded fallback data.
class FeaturedProfessionalsSection extends ConsumerStatefulWidget {
const FeaturedProfessionalsSection({super.key});
@@ -58,28 +28,50 @@ class FeaturedProfessionalsSection extends ConsumerStatefulWidget {
class _FeaturedProfessionalsSectionState
extends ConsumerState<FeaturedProfessionalsSection> {
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 - 80;
if (cardWidth <= 0) return;
final page = (_scrollController.offset / cardWidth).round();
if (page != _currentPage) {
setState(() => _currentPage = page);
}
}
@override
Widget build(BuildContext context) {
final homeState = ref.watch(homeProvider);
final topProfessionals = homeState.content?.topProfessionals;
// Real agent data from GET /agents API
final topProState = ref.watch(topProfessionalsProvider);
final professionals = topProState.agents;
// Use CMS agents if available, otherwise fallback to defaults (same as web)
final cmsAgents = topProfessionals?.agents ?? [];
final professionals = cmsAgents.isNotEmpty ? cmsAgents : _defaultAgents;
if (topProState.isLoading) {
return const Padding(
padding: EdgeInsets.symmetric(vertical: 40),
child: Center(
child: CircularProgressIndicator(color: AppColors.accentOrange),
),
);
}
if (professionals.isEmpty) {
return const SizedBox.shrink();
}
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 40),
@@ -88,14 +80,23 @@ class _FeaturedProfessionalsSectionState
// Card carousel
SizedBox(
height: 370,
child: PageView.builder(
controller: _pageController,
child: ListView.builder(
controller: _scrollController,
scrollDirection: Axis.horizontal,
physics: const BouncingScrollPhysics(),
itemCount: professionals.length,
onPageChanged: (index) {
setState(() => _currentPage = index);
},
itemBuilder: (context, index) {
return _buildFeaturedCard(professionals[index], index);
final cardWidth = MediaQuery.of(context).size.width - 80;
return SizedBox(
width: cardWidth,
child: Padding(
padding: EdgeInsets.only(
left: index == 0 ? 0 : 8,
right: index == professionals.length - 1 ? 0 : 8,
),
child: _buildFeaturedCard(professionals[index], index),
),
);
},
),
),
@@ -108,7 +109,12 @@ class _FeaturedProfessionalsSectionState
);
}
Widget _buildFeaturedCard(ProfessionalItem professional, int index) {
Widget _buildFeaturedCard(AgentProfile agent, int index) {
final rating = agent.averageRating ?? 0.0;
final ratingText = rating > 0 ? '${rating.toStringAsFixed(1)} Rating' : '';
final subtitle = agent.agentType?.name ?? agent.headline ?? '';
final experience = agent.experienceText;
return Container(
decoration: BoxDecoration(
color: Colors.white,
@@ -117,87 +123,90 @@ class _FeaturedProfessionalsSectionState
),
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, 14),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Name (Fractul Bold 16px)
Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 14),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Name
Text(
agent.fullName,
style: const TextStyle(
fontFamily: 'Fractul',
fontSize: 16,
fontWeight: FontWeight.w700,
color: AppColors.primaryDark,
),
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 2),
// Subtitle/headline
if (subtitle.isNotEmpty)
Text(
professional.name,
subtitle,
style: const TextStyle(
fontFamily: 'Fractul',
fontSize: 16,
fontWeight: FontWeight.w700,
fontSize: 14,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 2),
const SizedBox(height: 6),
// Subtitle (e.g. "Rental & Investment Consultant")
if (professional.subtitle.isNotEmpty)
Text(
professional.subtitle,
style: const TextStyle(
fontFamily: 'Fractul',
fontSize: 14,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 6),
// Verified + Rating row
Row(
children: [
// Verified + Rating row
Row(
children: [
if (agent.isVerified) ...[
SvgPicture.asset(
'assets/icons/verified_badge_icon.svg',
width: 19,
height: 19,
width: 16,
height: 16,
placeholderBuilder: (_) => const Icon(
Icons.verified,
color: Color(0xFF1DA1F2),
size: 19,
color: Color(0xFF638559),
size: 16,
),
),
const SizedBox(width: 6),
const Text(
'Verified Agent',
'\u201CVerified local agent\u201D',
style: TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w500,
color: AppColors.primaryDark,
color: Color(0xFF638559),
),
),
const SizedBox(width: 16),
],
if (ratingText.isNotEmpty) ...[
SvgPicture.asset(
'assets/icons/star_rating_icon.svg',
width: 19,
height: 19,
width: 16,
height: 16,
placeholderBuilder: (_) => const Icon(
Icons.star,
color: Color(0xFFFFDE21),
size: 19,
size: 16,
),
),
const SizedBox(width: 4),
const Text(
'4.9 Rating',
style: TextStyle(
Text(
ratingText,
style: const TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w400,
@@ -205,70 +214,70 @@ class _FeaturedProfessionalsSectionState
),
),
],
),
const SizedBox(height: 6),
],
),
const SizedBox(height: 6),
// Location row with filled icon
if (professional.location.isNotEmpty)
Row(
// Location row
if (agent.location.isNotEmpty)
Row(
children: [
SvgPicture.asset(
'assets/icons/location_filled_icon.svg',
width: 19,
height: 19,
placeholderBuilder: (_) => const Icon(
Icons.location_on,
color: AppColors.accentOrange,
size: 19,
),
),
const SizedBox(width: 6),
Expanded(
child: Text(
agent.location,
style: const TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w500,
color: AppColors.primaryDark,
),
overflow: TextOverflow.ellipsis,
),
),
],
),
const SizedBox(height: 8),
// Experience
if (experience.isNotEmpty)
RichText(
text: TextSpan(
children: [
SvgPicture.asset(
'assets/icons/location_filled_icon.svg',
width: 19,
height: 19,
placeholderBuilder: (_) => const Icon(
Icons.location_on,
color: AppColors.accentOrange,
size: 19,
const TextSpan(
text: 'Experience: ',
style: TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w700,
color: AppColors.primaryDark,
),
),
const SizedBox(width: 6),
Expanded(
child: Text(
professional.location,
style: const TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w500,
color: AppColors.primaryDark,
),
overflow: TextOverflow.ellipsis,
TextSpan(
text: experience,
style: const TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
),
),
],
),
const Spacer(),
// Experience
if (professional.experience.isNotEmpty)
RichText(
text: TextSpan(
children: [
const TextSpan(
text: 'Experience: ',
style: TextStyle(
fontFamily: 'SourceSerif4',
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,
),
],
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
),
],
@@ -276,10 +285,10 @@ class _FeaturedProfessionalsSectionState
);
}
// ── Image helpers ──
// -- Image helpers --
Widget _buildCardImage(ProfessionalItem professional, int index) {
final resolvedUrl = _resolveImageUrl(professional.imageUrl);
Widget _buildCardImage(AgentProfile agent, int index) {
final resolvedUrl = _resolveImageUrl(agent.avatarUrl);
if (resolvedUrl != null) {
return CachedNetworkImage(
imageUrl: resolvedUrl,
@@ -293,8 +302,8 @@ class _FeaturedProfessionalsSectionState
return _buildImagePlaceholder(index);
}
String? _resolveImageUrl(String imageUrl) {
if (imageUrl.isEmpty) return null;
String? _resolveImageUrl(String? imageUrl) {
if (imageUrl == null || imageUrl.isEmpty) return null;
if (imageUrl.startsWith('http://') || imageUrl.startsWith('https://')) {
return imageUrl;
}
@@ -319,7 +328,7 @@ class _FeaturedProfessionalsSectionState
);
}
// ── Dot indicators ──
// -- Dot indicators --
Widget _buildDotIndicators(int count) {
return Row(

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:real_estate_mobile/core/constants/app_colors.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';
@@ -14,15 +15,36 @@ const _defaultHero = HeroContent(
'Connect with trusted local agents to explore homes, compare options, and make smarter decisions.',
);
class HeroSection extends ConsumerWidget {
class HeroSection extends ConsumerStatefulWidget {
const HeroSection({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
ConsumerState<HeroSection> createState() => _HeroSectionState();
}
class _HeroSectionState extends ConsumerState<HeroSection> {
final _searchController = TextEditingController();
@override
void dispose() {
_searchController.dispose();
super.dispose();
}
void _navigateToSearch() {
final query = _searchController.text.trim();
if (query.isNotEmpty) {
context.push('/agents/search?q=${Uri.encodeComponent(query)}');
} else {
context.push('/agents/search');
}
}
@override
Widget build(BuildContext context) {
final homeState = ref.watch(homeProvider);
final hero = homeState.content?.hero ?? _defaultHero;
// Use CMS headline if available, otherwise fallback
final headline = hero.headline.isNotEmpty
? hero.headline
: _defaultHero.headline;
@@ -32,7 +54,6 @@ class HeroSection extends ConsumerWidget {
return Stack(
children: [
// Background image
ClipRRect(
borderRadius: BorderRadius.circular(0),
child: Image.asset(
@@ -42,7 +63,6 @@ class HeroSection extends ConsumerWidget {
fit: BoxFit.cover,
),
),
// Content overlay
Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: Column(
@@ -60,7 +80,6 @@ class HeroSection extends ConsumerWidget {
),
),
const SizedBox(height: 30),
// Search Agents Card
_buildSearchCard(ctaButtonText),
],
),
@@ -93,17 +112,44 @@ class HeroSection extends ConsumerWidget {
const SizedBox(height: 16),
_buildSearchField('Types'),
const SizedBox(height: 12),
_buildSearchField('Name or Keyword'),
// Name or Keyword — actual text input
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
),
child: TextField(
controller: _searchController,
style: const TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
),
decoration: const InputDecoration(
hintText: 'Name or Keyword',
hintStyle: TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
),
border: InputBorder.none,
contentPadding:
EdgeInsets.symmetric(horizontal: 20, vertical: 12),
),
onSubmitted: (_) => _navigateToSearch(),
),
),
const SizedBox(height: 12),
_buildSearchField('Location'),
const SizedBox(height: 12),
_buildSearchField('Categories'),
const SizedBox(height: 12),
// CTA button
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () {},
onPressed: _navigateToSearch,
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.primaryDark,
foregroundColor: Colors.white,
@@ -128,32 +174,40 @@ class HeroSection extends ConsumerWidget {
}
Widget _buildSearchField(String hint) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
),
child: Row(
children: [
Expanded(
child: Text(
hint,
style: const TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
return GestureDetector(
onTap: () {
// Tapping Types/Location/Categories navigates to search screen
if (hint == 'Types' || hint == 'Categories' || hint == 'Location') {
context.push('/agents/search');
}
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
),
child: Row(
children: [
Expanded(
child: Text(
hint,
style: const TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
),
),
),
),
if (hint == 'Types' || hint == 'Categories')
const Icon(
Icons.keyboard_arrow_down,
color: AppColors.primaryDark,
size: 20,
),
],
if (hint == 'Types' || hint == 'Categories')
const Icon(
Icons.keyboard_arrow_down,
color: AppColors.primaryDark,
size: 20,
),
],
),
),
);
}

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,

View File

@@ -1,19 +1,69 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:real_estate_mobile/core/constants/app_colors.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';
class TrustStatsSection extends StatelessWidget {
/// Default content — matches web's hardcoded defaultContent fallback.
const _defaultContent = TestimonialsContent(
title: "Our Clients' Trust Is Our Foundation",
subtitle:
'We help buyers, sellers, and investors close successful real estate deals with confidence in every transaction.',
ratingInfo:
'Clients rate our real estate services 4.9 out of 5 on average, based on recent client reviews.',
stats: [
StatItem(
iconPath: 'cities',
boldText: '25+ Cities &',
normalText: 'neighborhoods served',
),
StatItem(
iconPath: 'properties',
boldText: '1,000+ Properties',
normalText: 'bought and sold for our clients.',
),
],
testimonials: [],
);
/// Map of stat icon keys to local SVG asset paths and Material fallback icons.
const _statIconMap = {
'cities': ('assets/icons/cities_icon.svg', Icons.location_city),
'properties': ('assets/icons/properties_icon.svg', Icons.home_work),
};
class TrustStatsSection extends ConsumerWidget {
const TrustStatsSection({super.key});
@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
final homeState = ref.watch(homeProvider);
final cmsTestimonials = homeState.content?.testimonials;
// Use CMS data if available, otherwise fallback (same pattern as web)
final data = cmsTestimonials ?? _defaultContent;
final title = data.title.isNotEmpty ? data.title : _defaultContent.title;
final subtitle =
data.subtitle.isNotEmpty ? data.subtitle : _defaultContent.subtitle;
final ratingInfo = data.ratingInfo.isNotEmpty
? data.ratingInfo
: _defaultContent.ratingInfo;
final stats =
data.stats.isNotEmpty ? data.stats : _defaultContent.stats;
// Extract rating number from ratingInfo string (e.g. "4.9" from "...4.9 out of 5...")
final ratingValue = _extractRating(ratingInfo);
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column(
children: [
const Text(
"Our Clients' Trust Is Our Foundation",
Text(
title,
textAlign: TextAlign.center,
style: TextStyle(
style: const TextStyle(
fontFamily: 'Fractul',
fontSize: 25,
fontWeight: FontWeight.w700,
@@ -21,10 +71,10 @@ class TrustStatsSection extends StatelessWidget {
),
),
const SizedBox(height: 16),
const Text(
'We help buyers, sellers, and investors close successful real estate deals with confidence in every transaction.',
Text(
subtitle,
textAlign: TextAlign.center,
style: TextStyle(
style: const TextStyle(
fontFamily: 'Fractul',
fontSize: 14,
fontWeight: FontWeight.w500,
@@ -32,10 +82,10 @@ class TrustStatsSection extends StatelessWidget {
),
),
const SizedBox(height: 8),
const Text(
'Clients rate our real estate services 4.9 out of 5 on average, based on recent client reviews.',
Text(
ratingInfo,
textAlign: TextAlign.center,
style: TextStyle(
style: const TextStyle(
fontFamily: 'Fractul',
fontSize: 14,
fontWeight: FontWeight.w500,
@@ -49,92 +99,142 @@ class TrustStatsSection extends StatelessWidget {
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Cities stat
// Dynamic stats from CMS
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
RichText(
text: const TextSpan(
children: [
TextSpan(
text: '25+ Cities &\n',
style: TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w700,
color: AppColors.primaryDark,
),
),
TextSpan(
text: 'neighborhoods served',
style: TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
),
),
],
),
),
const SizedBox(height: 12),
RichText(
text: const TextSpan(
children: [
TextSpan(
text: '1,000+ Properties\n',
style: TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w700,
color: AppColors.primaryDark,
),
),
TextSpan(
text: 'bought and sold for our clients.',
style: TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
),
),
],
),
),
],
children: stats
.map((stat) => Padding(
padding: const EdgeInsets.only(bottom: 12),
child: _buildStatItem(stat),
))
.toList(),
),
),
// Rating visual
const SizedBox(width: 16),
Column(
children: [
const Text(
'4.9',
style: TextStyle(
fontFamily: 'Fractul',
fontSize: 32,
fontWeight: FontWeight.w700,
color: AppColors.primaryDark,
),
),
Row(
children: List.generate(
5,
(index) => Icon(
index < 4 ? Icons.star : Icons.star_half,
color: AppColors.accentOrange,
size: 18,
),
),
),
],
),
_buildRatingVisual(ratingValue),
],
),
],
),
);
}
Widget _buildStatItem(StatItem stat) {
final iconEntry = _statIconMap[stat.iconPath];
final svgPath = iconEntry?.$1;
final fallbackIcon = iconEntry?.$2 ?? Icons.info_outline;
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (svgPath != null)
Padding(
padding: const EdgeInsets.only(right: 8, top: 2),
child: SvgPicture.asset(
svgPath,
width: 27,
height: 27,
placeholderBuilder: (_) => Icon(
fallbackIcon,
size: 27,
color: AppColors.accentOrange,
),
),
)
else
Padding(
padding: const EdgeInsets.only(right: 8, top: 2),
child: Icon(
fallbackIcon,
size: 27,
color: AppColors.accentOrange,
),
),
Expanded(
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: '${stat.boldText}\n',
style: const TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w700,
color: AppColors.primaryDark,
),
),
TextSpan(
text: stat.normalText,
style: const TextStyle(
fontFamily: 'SourceSerif4',
fontSize: 14,
fontWeight: FontWeight.w400,
color: AppColors.primaryDark,
),
),
],
),
),
),
],
);
}
Widget _buildRatingVisual(double rating) {
final fullStars = rating.floor();
final hasHalfStar = (rating - fullStars) >= 0.3;
final totalStars = 5;
return Column(
children: [
Text(
rating.toStringAsFixed(1),
style: const TextStyle(
fontFamily: 'Fractul',
fontSize: 32,
fontWeight: FontWeight.w700,
color: AppColors.primaryDark,
),
),
Row(
children: List.generate(
totalStars,
(index) {
if (index < fullStars) {
return const Icon(
Icons.star,
color: AppColors.accentOrange,
size: 18,
);
} else if (index == fullStars && hasHalfStar) {
return const Icon(
Icons.star_half,
color: AppColors.accentOrange,
size: 18,
);
} else {
return const Icon(
Icons.star_border,
color: AppColors.accentOrange,
size: 18,
);
}
},
),
),
],
);
}
/// Extract numeric rating from ratingInfo string.
/// e.g. "Clients rate our real estate services 4.9 out of 5..." → 4.9
double _extractRating(String ratingInfo) {
final match = RegExp(r'(\d+\.?\d*)\s*out\s*of\s*\d+').firstMatch(ratingInfo);
if (match != null) {
return double.tryParse(match.group(1)!) ?? 4.9;
}
return 4.9;
}
}