Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter icons not centred in Iconbutton and alignment does nothing

The icons need to be centred within the Icon buttons otherwise when the two are centred together in the middle of the row, they appear slightly off centre to the right.

Row(
  children: <Widget>[
    IconButton(
      alignment: Alignment.center,
      icon: Icon(Icons.arrow_left,
          color: Color(0xFFF89CC0), size: 42),
      onPressed: () {},
    ),
    IconButton(
      alignment: Alignment.topLeft,
      icon: Icon(Icons.arrow_right,
          color: Color(0xFFF89CC0), size: 42),
      onPressed: () {},
      },
    ),
  ],
),

I have alignment parameters set which as you can see in the screenshot are completely ignored:

enter image description here

How can I get them to be in the centre of their button?

like image 453
Hasen Avatar asked Jul 30 '19 07:07

Hasen


1 Answers

The problem is that IconButtons have a default padding, so do it like this:

return Row(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: <Widget>[
        IconButton(
          padding: EdgeInsets.all(0),
          icon: Icon(Icons.arrow_left, color: Color(0xFFF89CC0), size: 42),
          onPressed: () => {},
        ),
        IconButton(
          padding: EdgeInsets.all(0),
          icon: Icon(Icons.arrow_right, color: Color(0xFFF89CC0), size: 42),
          onPressed: () {},
        ),
      ],
    );
like image 170
Julien Lachal Avatar answered Nov 08 '22 19:11

Julien Lachal