I’m trying to center my Text and two icon buttons which are the arrows in the middle. I tried adding padding but it seems kind of brute force, wondering if there was a proper way for this.
return Scaffold(
appBar: AppBar(
title: Row(
children: [
IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
// do something when the back arrow button is tapped
},
color: Colors.black,
),
Text(
'Today',
style: TextStyle(
color: Colors.black, // set the color of the title text
),
),
IconButton(
icon: Icon(Icons.arrow_forward),
onPressed: () {
// do something when the forward arrow button is tapped
},
color: Colors.black,
),
],
),
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
centerTitle: true,
leading: IconButton(
icon: Icon(
Icons.menu,
color: Colors.black,
),
onPressed: () {},
),
actions: [
Padding(
padding: EdgeInsets.only(
right: 12.0), // set the horizontal padding to 16.0
child: IconButton(
icon: Icon(
Icons.settings,
color: Colors
.black, // set the color of the search icon button to white
),
onPressed: () {},
),
),
],
elevation: 0,
),
I also saw that you can add a spacer widget but don’t think that’s wise.
2
Answers
I just needed to wrap the widget with a center widget with
mainAxisAlignment
There are two possible solutions:
or