Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to align AppBar to center Flutter

I have a problem. I have an app with page navigations, and when I navigate to another page, a back arrow appears in the AppBar, which moves the text to the side. And I need it to be constantly in the center

Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(icon: Icon(Icons.account_circle_rounded), onPressed: () {  },),
        title: Align(
          alignment: Alignment.center,
          child: Text('Some text'),
        ),
      ),
      body: Container(...)

This is the AppBar Code

Navigator.push(context, MaterialPageRoute(
              builder: (context) => OrderWidget())
          );

In this way I go to a new page

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Instead of Align your title, set centerTitle true in your AppBar for center title, like this:

appBar: AppBar(
            centerTitle: true,
            leading: IconButton(
              icon: Icon(Icons.account_circle_rounded),
              onPressed: () {},
            ),
            title: Text('Some text'),
          ),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading