将堆栈中的行居中

问题描述 投票:0回答:1

我有一个小部件,它由堆栈中的行和图标组成。我想将它们在堆栈中垂直居中放置(中间的行,右边的图标)。我将两个小部件都包装在Align小部件中,但这仅影响图标,而不影响行。 ROW如何垂直居中?

这是我的代码

@override
Widget build(BuildContext context) {
  return Card(
    child: Padding(
      padding: EdgeInsets.all(16.0),
      child: Stack(
        children: <Widget>[
          Align(
            alignment: Alignment.center,
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(searchLanguage == SearchLanguage.english ? word.english : word.korean,
                    style: Theme.of(context).textTheme.bodyText1),
                SizedBox(
                  width: 8.0,
                ),
                Icon(Icons.arrow_forward),
                SizedBox(
                  width: 8.0,
                ),
                Text(searchLanguage == SearchLanguage.english ? word.korean : word.english,
                    style: Theme.of(context).textTheme.bodyText1),
              ],
            ),
          ),
          Align(
            alignment: Alignment.centerRight,
            child: IconButton(
              icon: Icon(Icons.delete),
              onPressed: () => deleteCallback(word),
            ),
          )
        ],
      ),
    ),
  );
}

这是结果

enter image description here

flutter flutter-layout
1个回答
0
投票

尝试通过不使用Align包裹Row小部件,而使用它们将其保持在中心。

crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
© www.soinside.com 2019 - 2024. All rights reserved.