text
stringlengths
1
474
<topic_start>
Update the app to display the title section
Add the TitleSection widget as the first element in the children list.
This places it at the top of the screen.
Pass the provided name and location to the TitleSection constructor.lightbulb Tip<topic_end>
<topic_start>
Add the Button section
In this section, add the buttons that will add functionality to your app.The Button section contains three columns that use the same layout:
an icon over a row of text.Plan to distribute these columns in one row so each takes the same
amount of space. Paint all text and icons with the primary color.<topic_end>
<topic_start>
Add the ButtonSection widget
Add the following code after the TitleSection widget to contain the code
to build the row of buttons.
<code_start>class ButtonSection extends StatelessWidget {
const ButtonSection({super.key});
@override
Widget build(BuildContext context) {
final Color color = Theme.of(context).primaryColor;
// ···
}
}<code_end>
<topic_end>
<topic_start>
Create a widget to make buttons
As the code for each column could use the same syntax,
create a widget named ButtonWithText.
The widget’s constructor accepts a color, icon data, and a label for the button.
Using these values, the widget builds a Column with an Icon and a stylized
Text widget as its children.
To help separate these children, a Padding widget the Text widget
is wrapped with a Padding widget.Add the following code after the ButtonSection class.
<code_start>class ButtonSection extends StatelessWidget {
const ButtonSection({super.key});
// ···
}
class ButtonWithText extends StatelessWidget {
const ButtonWithText({
super.key,
required this.color,
required this.icon,
required this.label,
});
final Color color;
final IconData icon;
final String label;
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(icon, color: color),
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
label,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w400,
color: color,
),
),
),
],
);
}<code_end>
<topic_end>
<topic_start>
Position the buttons with a Row widget
Add the following code into the ButtonSection widget.
<code_start>class ButtonSection extends StatelessWidget {
const ButtonSection({super.key});
@override
Widget build(BuildContext context) {
final Color color = Theme.of(context).primaryColor;
return SizedBox(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ButtonWithText(
color: color,
icon: Icons.call,
label: 'CALL',
),
ButtonWithText(
color: color,
icon: Icons.near_me,
label: 'ROUTE',
),
ButtonWithText(
color: color,
icon: Icons.share,
label: 'SHARE',
),
],
),
);
}
}