【发布时间】:2021-09-14 17:28:44
【问题描述】:
我有一个高度可以变化的文本,后跟一个 PopupMenuButton。我希望文本在垂直轴上居中对齐(这样当只有 1 线文本时就不会出现奇怪的空白),但无论文本的高度如何,PopupMenuButton 都保持在右上角.因此使用 crossAxisAlignement 在这里不起作用,因为所有小部件都会受到影响。在文本或 PopupMenuButton 上使用 Align 小部件不起作用,而 textAlign 也不起作用似乎任何解决方案都必须在 Row 级别而不是在其子级中实现,这是有道理的。
现在我使用 Row 来包含这 2 个小部件,但如果我想要之前提到的行为,我不太确定它是否是我所需要的。是否有针对 Row 的解决方案,或者我可以为此使用的其他小部件?
下面是代码。谢谢。
Row(
children: [
Expanded(
child: RichText(
text: TextSpan(), // bunch of text in there
)
)
),
SizedBox( // To box in the 3 dots icon (material design forces 48px otherwise)
height: 24,
width: 24,
child: PopupMenuButton(
padding: EdgeInsets.all(0),
onSelected: menuSelect,
itemBuilder: (BuildContext context) {
return [
PopupMenuItem(value: 0, child: Text('Read', textAlign: TextAlign.center,),),
PopupMenuItem(value: 1, child: Text('Delete', textAlign: TextAlign.center,),)
];
},
),
)
],
)
【问题讨论】:
标签: flutter alignment row-height