feat: Implement agent search functionality and update the home screen to dynamically display professional data.
This commit is contained in:
@@ -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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user