如何将中间元素集中在一行 3 个元素中(其中每个元素具有不同的长度),我希望侧面元素最大程度地位于左侧/右侧,而中间元素恰好位于中间?
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Container(
child: Text(
'el',
style: TextStyle(
fontSize: 16,
color: Color(0xFFD50000),
),
),
)),
Expanded(
child: Container(
child: Text('elem',
style: TextStyle(
color: Colors.black,
fontSize: 16,
)),
)),
Expanded(
child: Container(
child: Text('longest elem',
style: TextStyle(
fontSize: 16,
color: Color(0xFFD50000),
)),
)),
],
)
当您使用
Expanded
时,每个人都会变得灵活:1。现在您可以使用 Container 中的 align
,然后使用 textAlign
使其居中(只需要其中之一)。
Expanded(
child: Container(
alignment: Alignment.center,
child: Text(
'elem',
textAlign: TextAlign.center, //may work without it
style: TextStyle(
color: Colors.black,
fontSize: 16,
),
),
),
),