Sadam Khan
Sadam Khan

Reputation: 85

Center align issue with Drawer

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."))],
        ),
      ),
    );
  }
}

enter image description here

Upvotes: 0

Views: 615

Answers (1)

KuKu
KuKu

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"),
          ],
        ),
      ),

enter image description here

Upvotes: 2

Related Questions