build method
- BuildContext context
Describes the part of the user interface represented by this widget.
The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). This method can potentially be called in every frame and should not have any side effects beyond building a widget.
The framework replaces the subtree below this widget with the widget returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the widget returned by this method can update the root of the existing subtree, as determined by calling Widget.canUpdate.
Typically implementations return a newly created constellation of widgets that are configured with information from this widget's constructor and from the given BuildContext.
The given BuildContext contains information about the location in the tree at which this widget is being built. For example, the context provides the set of inherited widgets for this location in the tree. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.
The implementation of this method must only depend on:
- the fields of the widget, which themselves must not change over time, and
- any ambient state obtained from the
context
using BuildContext.dependOnInheritedWidgetOfExactType.
If a widget's build method is to depend on anything else, use a StatefulWidget instead.
See also:
- StatelessWidget, which contains the discussion on performance considerations.
Implementation
@override
Widget build(BuildContext context) {
// Localization instance for accessing localized strings.
final tr = AppLocalizations.of(context)!;
return Stack(
// Allows children to overflow the stack's bounds.
clipBehavior: Clip.none,
children: [
// Main container holding the content of the overview section.
Container(
// Padding around the content inside the container.
padding: const EdgeInsets.all(AppConstants.padding),
// Background color of the section.
color: AppConstants.primarySectionColor,
// Expand the container to fill the available width.
width: double.infinity,
child: Column(
// Align children to the start of the column.
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Title text of the overview section.
Text(tr.creativeHands, style: const TextStyle(fontSize: 20)),
// Spacer between title and description.
const SizedBox(height: 16),
// Description text of the overview section.
SizedBox(
// Width of the description text container.
width: 0.90.sw,
child: Text(
tr.overviewDescription,
style: const TextStyle(fontSize: 16),
),
),
// Spacer between description and button.
const SizedBox(height: 35),
// Button to navigate to the About App page.
CupertinoButtonFilledComponent(
onPressed: () {
// Navigate to the About App page on button press.
Navigator.push(
context,
CupertinoPageRoute(builder: (context) => const AboutApp()),
);
},
text: tr.aboutQissatHirfati,
),
// Spacer below the button.
const SizedBox(height: 16),
],
),
),
// Positioned image for decorative purposes.
Positioned(
// Align image to the left, top and bottom of the stack.
left: 0,
top: 0,
bottom: 0,
child: Image.asset(
// Image asset path.
AppConstants.smallTreePNG,
// Fit image within its bounds while maintaining aspect ratio.
fit: BoxFit.contain,
// Quality of image rendering.
filterQuality: FilterQuality.high,
// Opacity level of the image.
opacity: const AlwaysStoppedAnimation(.5),
),
),
],
);
}