This is my app bar with one line text:
appBar: AppBar(
title: Text("Summer Trip"),
centerTitle: true,
actions: [
PopupMenuButton(
itemBuilder: (context){
return [
PopupMenuItem<int>(
value: 0,
child: Text("Test"),
),
];
},
),
],
),
And it gives the following result:
As you see the center of the row is about 25 pixels from screen border.
Now I need to add the second line to my title. This is my solution:
appBar: AppBar(
toolbarHeight: 70,
flexibleSpace: SafeArea(
child: Center(
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 10),
child: Text('Summer Trip',
style: TextStyle(color: Colors.white, fontWeight: FontWeight.w500, fontSize: 20.0)
),
),
Padding(
padding: const EdgeInsets.only(top: 5),
child: Text('Step 1',
style: TextStyle(color: Colors.white54, fontWeight: FontWeight.normal, fontSize: 14.0)
),
),
],
),
),
),
actions: [
PopupMenuButton(
itemBuilder: (context){
return [
PopupMenuItem<int>(
value: 0,
child: Text("Test"),
),
];
},
),
],
),
And this is the result:
As you see, if we increase toolbarHeight
of AppBar
then arrow and menu buttons move down. However, I need them to stay at the same position. Could anyone say how to do it?
2
Answers
You can wrap your widgets with Align widget.
Output:
Thanks to @Pavel_K for correcting me, earlier I misunderstood the question.
Corrected Answer
Instead of using
flexibleSpace
, usetitle
(for the main title) andbottom
(for the subtitle). This approach will solve your query, and make the icons stay on top (along the center of the title).Old (incorrect) Answer
I think you are using the
flexibleSpace
with the incorrect intent; it is meant to be used with FlexibleSpaceBar.What you want to achieve can be simply achieved using
title
property ofAppBar
, and it will center the icon on it’s own.It will look like this: