垂直对齐行中的项目

时间:2018-12-29 16:24:26

标签: flutter

我不知道如何将图标按钮连续垂直对齐。这是我的代码:

        Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            IconButton(
              icon: Icon(Icons.fast_rewind, size: 30),
              alignment: Alignment.center,
              onPressed: workoutBloc.player.hasPrevExercise ?  workoutBloc.player.previousExercise : null,
            ),
            IconButton(
              icon: Icon(Icons.skip_previous, size: 30),
              onPressed: workoutBloc.player.hasPrevSet ? workoutBloc.player.previousSet : null
            ),
            IconButton(
              icon: workoutBloc.player.isPlaying ? Icon(Icons.pause, size: 45) : Icon(Icons.play_arrow, size: 45),
              onPressed: workoutBloc.player.hasEnded ? null :  () {
                setState(() {});
                workoutBloc.playPause();
              },
            ),
            IconButton(
              icon: Icon(Icons.stop, size: 45,),
              onPressed: workoutBloc.player.state != 'REST' ? () {
                workoutBloc.stopSet();
              } : null
            ),
            IconButton(
              icon: Icon(Icons.skip_next, size: 30),
              onPressed: workoutBloc.player.hasNextSet ? workoutBloc.player.nextSet : null,
            ),
            IconButton(
              icon: Icon(Icons.fast_forward, size: 30),
              onPressed: workoutBloc.player.hasNextExercise ? workoutBloc.player.nextExercise : null
            )
          ],
        )

我已经将crossAxisAlignemnt设置为居中,但是那没用。我也为alignment: Alignment.center的图标按钮感到疲倦,但是它也不起作用。看起来像这样:

enter image description here

1 个答案:

答案 0 :(得分:3)

因此,可以在Flutter Inspector的帮助下看到问题。您正在更改图标对象中的图标大小。因此,父IconButton不会包装它的大小,而是在推它。

enter image description here

要修复该问题,如果将图标的大小移动到iconSize的{​​{1}}属性,您将拥有所需的内容。

IconButton

enter image description here