Reputation: 85
The title in AppBar was center align but as soon I added Drawer, the title pushed towards the right of the screen. How do I achieve center alignment?
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Center(child: Text("Chalo")),
),
drawer: MainDrawer(),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [Center(child: Text("You are on a homepage."))],
),
),
);
}
}
Upvotes: 0
Views: 615
Reputation: 7492
Just add centerTitle: true to AppBar widget.
AppBar(
centerTitle: true,
title: Text("Chalo"),
),
Or change Center widget to Row widget and give a MainAxisSize.min to mainAxisSize parameter.
AppBar(
title: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text("Chalo"),
],
),
),
Upvotes: 2