您只需强制文本分配行的剩余空间:通过设置fit: FlexFit.tight
,使灵活小部件等于Expanded
小部件
Container(
padding: EdgeInsets.symmetric(horizontal: 15),
child: Row(children: [
Flexible(
fit: FlexFit.tight,
child: Text(
"",
),
),
IconButton(
onPressed: () {},
icon: const Icon(
Icons.copy,
),
),
]),
)
注:SizedBox
已被填充取代.
或者,您可以在文本和图标按钮之间放置间隔符:
Text(
"",
),
Spacer(),
IconButton(
onPressed: () {},
icon: const Icon(
Icons.copy,
),
),
或将Row的mainAxisAlignment
设置为spaceBetween
.
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"",
),
IconButton(
onPressed: () {},
icon: const Icon(
Icons.copy,
),
),
]),
希望对你有帮助.