您需要注意的主要事情是,如果您不想使用Stack
您应该在左侧和右侧提供相同的宽度消耗小部件。
我会这样做Expanded
and Padding
Row(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 32.0),
child: Text(
"Text",
textAlign: TextAlign.center,
),
),
),
Icon(Icons.add, size: 32.0,)
],
)
or with Row
's mainAxisAlignment
and a SizedBox
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
const SizedBox(width: 32.0),
Text("Text"),
Icon(Icons.add, size: 32.0)
],
)
or with Expanded
and a SizedBox
在左边而不是填充:)。左侧的填充或额外容器是为了使 textAlign 能够真正将行中的文本居中,同时考虑到图标占用的空间。