feat: implement dynamic content loading for home sections with Riverpod and default fallbacks.

This commit is contained in:
pradeepkumar
2026-02-25 07:48:02 +05:30
parent c9366dedd0
commit 379fbfe0a8
3 changed files with 238 additions and 84 deletions

View File

@@ -1,11 +1,35 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.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 HeroSection extends StatelessWidget {
/// Default hero content — matches web's hardcoded defaultHeroContent fallback.
const _defaultHero = HeroContent(
headline:
'Discover verified, top-rated real estate professionals to guide your buying, selling, or investing journey.',
description: 'Discover verified, top-rated real estate professionals',
ctaButtonText: 'See All Agents',
helperText:
'Connect with trusted local agents to explore homes, compare options, and make smarter decisions.',
);
class HeroSection extends ConsumerWidget {
const HeroSection({super.key});
@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
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;
final ctaButtonText = hero.ctaButtonText.isNotEmpty
? hero.ctaButtonText
: _defaultHero.ctaButtonText;
return Stack(
children: [
// Background image
@@ -24,10 +48,10 @@ class HeroSection extends StatelessWidget {
child: Column(
children: [
const SizedBox(height: 40),
const Text(
'Discover verified, top-rated real estate professionals.',
Text(
headline,
textAlign: TextAlign.center,
style: TextStyle(
style: const TextStyle(
fontFamily: 'Fractul',
fontSize: 30,
fontWeight: FontWeight.w700,
@@ -37,7 +61,7 @@ class HeroSection extends StatelessWidget {
),
const SizedBox(height: 30),
// Search Agents Card
_buildSearchCard(),
_buildSearchCard(ctaButtonText),
],
),
),
@@ -45,7 +69,7 @@ class HeroSection extends StatelessWidget {
);
}
Widget _buildSearchCard() {
Widget _buildSearchCard(String ctaButtonText) {
return Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
@@ -75,7 +99,7 @@ class HeroSection extends StatelessWidget {
const SizedBox(height: 12),
_buildSearchField('Categories'),
const SizedBox(height: 12),
// See All Agents button
// CTA button
SizedBox(
width: double.infinity,
child: ElevatedButton(
@@ -88,9 +112,9 @@ class HeroSection extends StatelessWidget {
borderRadius: BorderRadius.circular(10),
),
),
child: const Text(
'See All Agents',
style: TextStyle(
child: Text(
ctaButtonText,
style: const TextStyle(
fontFamily: 'Fractul',
fontSize: 16,
fontWeight: FontWeight.w700,