我有一行,两边各有一个图标,中间是带有图标的文本:
@override
Widget build(BuildContext context) {
return Row(
children: [
Icon(Icons.arrow_back),
Expanded(child: SizedBox()),
Icon(Icons.account_box),
Text("Some Text Here ", maxLines: 1), // ➜ This is the text.
Expanded(child: SizedBox()),
Icon(Icons.arrow_forward),
],
);
}
当文本足够长以填满整个空间时,我想使用FittedBox
使其变小。所以我尝试了这个:
FittedBox(child: Text("Some Text Here. More. More. More. More. More. More. More. More. ", maxLines: 1)),
它不能正常工作(溢出)。 我认为问题在于Row
没有告诉FittedBox
它可以拥有的最大尺寸。我已经尝试过使用Expanded
,IntrinsicWidth
,UnconstrainedBox
,Flexible
和Align
与FittedBox
一起使用,但都无法解决问题。
我该如何解决这个问题?
更新:我写了一篇文章,这篇文章将帮助我解决这个问题:https://medium.com/flutter-community/flutter-the-advanced-layout-rule-even-beginners-must-know-edc9516d1a2