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

Flutter row alignment

i would like to have the title exactly in the center of the screen and not the same distance between the other two row children.

Currently I have a row with mainAxisAlignment set to spaceBetween but this is not what I am looking for.

          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Container(
                width: 35,
                height: 35,
                decoration: const BoxDecoration(
                    shape: BoxShape.circle,
                    image: DecorationImage(image: NetworkImage("...")),
                    color: Colors.white),
              ),
              const Text(
                "TITLE",
                style: TextStyle(
                  fontFamily: "IBM",
                  fontWeight: FontWeight.bold,
                  fontSize: 20,
                  color: Colors.black,
                ),
              ),
              Timer(),
            ],

enter image description here

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 :

If you like to have appBar, use centerTitle: true, on appBar.

appBar: AppBar(
  title: Text("C"),
  centerTitle: true,
  leading: Container(
    width: 35,
    height: 35,
    decoration: const BoxDecoration(
        shape: BoxShape.circle,
        image: DecorationImage(image: NetworkImage("...")),
        color: Color.fromARGB(255, 24, 11, 11)),
  ),
  actions: [
    CircleAvatar(
      backgroundColor: Colors.red,
    ),
  ],
),

enter image description here
While the height is fixed, you can use Stack widget.

SizedBox(
  width: MediaQuery.of(context).size.width,
  height: 35,
  child: Stack(
    children: [
      Align(
        alignment: Alignment.centerLeft,
        child: Container(
          width: 35,
          height: 35,
          decoration: const BoxDecoration(
              shape: BoxShape.circle,
              image: DecorationImage(image: NetworkImage("...")),
              color: Color.fromARGB(255, 24, 11, 11)),
        ),
      ),
      Align(
        alignment: Alignment.center,
        child: const Text(
          "TITLE",
          style: TextStyle(
            fontFamily: "IBM",
            fontWeight: FontWeight.bold,
            fontSize: 20,
            color: Colors.black,
          ),
        ),
      ),
      Align(
        alignment: Alignment.centerRight,
        child: CircleAvatar(
          backgroundColor: Colors.red,
        ),
      )
    ],
  ),
),

You can also use Positioned widget to align the items.

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