颤振图标未在Iconbutton中居中并且对齐不起作用

时间:2019-07-30 07:12:20

标签: flutter dart alignment

图标必须在“图标”按钮中居中,否则当两个图标在行中间居中放置时,它们会稍微偏离右侧中心。

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: () {},
      },
    ),
  ],
),

我设置了alignment个参数,正如您在屏幕快照中看到的那样,这些参数被完全忽略:

https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onafterprint

如何使它们位于按钮的中央?

1 个答案:

答案 0 :(得分:1)

问题是IconButton具有默认填充,因此请执行以下操作:

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: () {},
        ),
      ],
    );