build method
- BuildContext context
override
Builds the home page widget tree.
This method returns a CupertinoPageScaffold widget that contains:
- A CupertinoNavigationBar with a title and a button to navigate to the settings page.
- A SingleChildScrollView that contains a Column with various sections and interactive elements.
The CupertinoNavigationBar uses a leading CupertinoButtonComponent to navigate to the SettingsPage. The main content is arranged in a column with multiple ArticleSectionComponent widgets.
BuildContext is the context in which the widget is built.
Implementation
@override
Widget build(BuildContext context) {
// Localized text instance for the current build context.
final tr = AppLocalizations.of(context)!;
// Controller for managing the horizontal scrolling of the PageView.
final pageController = PageController();
return CupertinoPageScaffold(
// Navigation bar with the app title and a button to open settings.
navigationBar: CupertinoNavigationBar(
middle: Text(tr.appTitle),
enableBackgroundFilterBlur: true,
leading: CupertinoButtonComponent(
icon: const Icon(CupertinoIcons.bars, size: AppConstants.iconSize),
onPressed: () {
// Navigate to the SettingsPage when the button is pressed.
Navigator.push(
context,
CupertinoSheetRoute(builder: (context) => const SettingsPage()),
);
},
),
),
// Main content of the home page within a scroll view.
child: SingleChildScrollView(
physics: const ScrollPhysics(),
child: Column(
children: [
// Introduction section at the top of the page.
const Landing(),
// Overview section providing a brief description of the app.
const OverviewSection(),
// Heritage section with a description and clickable image.
ArticleSectionComponent(
title: tr.heritage,
useChild: true,
useButton: true,
onPressed: () {
// Navigate to the OurHistory page when pressed.
Navigator.push(
context,
CupertinoPageRoute(builder: (context) => const OurHistory()),
);
},
description: tr.heritage_description,
child: Column(
spacing: 8,
children: [
const SizedBox(height: 8),
const AppDivider(),
Text(tr.bisht_description),
const SizedBox(height: 4),
CupertinoButton(
padding: EdgeInsets.zero,
onPressed: () {
// Launch URL when the image is clicked.
UrlRunServices.launchURL(
AppConstants.mohammedbinSalmanAlSaudLink,
);
},
child: Container(
decoration: const BoxDecoration(
boxShadow: [
BoxShadow(
color: CupertinoColors.darkBackgroundGray,
blurRadius: 4,
),
],
),
child: Image.asset(
AppConstants.mohammedbinSalmanAlSaudPNG,
),
),
),
],
),
),
// Work section with horizontally scrollable image gallery.
ArticleSectionComponent(
title: tr.ourWork,
useChild: true,
useButton: false,
onPressed: () {},
color: AppConstants.primarySectionColor,
description: tr.ourWork_description,
child: Column(
spacing: 8,
children: [
SizedBox(width: 0.5.sw, child: const AppDivider()),
SizedBox(
height: 280,
child: PageView(
controller: pageController,
scrollDirection: Axis.horizontal,
children: [
Column(
spacing: 8,
children: [
Image.asset(AppConstants.greenOrbPNG),
const Text('Qissat Hirfati'),
],
),
Column(
spacing: 8,
children: [
Image.asset(AppConstants.treesPNG),
const Text('Mohammed bin Salman Al Saud'),
],
),
Column(
spacing: 8,
children: [
Image.asset(AppConstants.pathPNG),
const Text('Small Tree'),
],
),
Column(
spacing: 8,
children: [
Image.asset(AppConstants.lampPNG),
const Text('Qissat Hirfati'),
],
),
],
),
),
SmoothPageIndicator(
controller: pageController,
count: 4,
effect: WormEffect(
activeDotColor: Theme.of(context).primaryColor,
),
),
const SizedBox(height: 8),
CupertinoButtonFilledComponent(
onPressed: () {
// Show dialog when the button is pressed.
CupertinoFeatureWillBeAvailableLaterDilog.show(context);
},
child: Text(tr.more),
),
Row(
spacing: 8,
children: [
Text(
tr.successPartners,
style: const TextStyle(fontWeight: FontWeight.bold),
),
const Expanded(child: AppDivider()),
],
),
SizedBox(
height: 80,
child: PageView(
children: [
Image.asset(
AppConstants.trs2PNG,
filterQuality: FilterQuality.high,
),
Image.asset(
AppConstants.trsPNG,
filterQuality: FilterQuality.high,
fit: BoxFit.cover,
),
Image.asset(
AppConstants.trs3PNG,
filterQuality: FilterQuality.high,
fit: BoxFit.cover,
),
Image.asset(
AppConstants.trs4PNG,
filterQuality: FilterQuality.high,
fit: BoxFit.contain,
),
],
),
),
],
),
),
],
),
),
);
}