我有一排,每边都有一个图标,然后是中间有一个图标的文本:
@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),
],
);
}
Run Code Online (Sandbox Code Playgroud)
当文本变得足够大以填满整个空间时,我想让 aFittedBox
变得更小。所以我试过这个:
FittedBox(child: Text("Some Text Here. More. More. More. More. More. More. More. More. ", maxLines: 1)),
Run Code Online (Sandbox Code Playgroud)
它不起作用(它溢出)。我相信问题在于Row
它没有说明FittedBox
它可能具有的最大尺寸。我曾考虑使用FittedBox
with Expanded
, IntrinsicWidth
, UnconstrainedBox
, Flexible
and Align
,但无济于事。
我该如何解决这个问题?
更新:我写了一篇可以帮助我解决这个问题的文章:https : //medium.com/flutter-community/flutter-the-advanced-layout-rule-even-beginners-must-know-edc9516d1a2
anm*_*ail 22
据我了解,您需要根据文本长度将文本放入行内。
工作代码:
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Icon(Icons.arrow_back),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.account_box),
Flexible(
child: FittedBox(
fit: BoxFit.scaleDown,
child: Text(
" Text HereSome Text Here Text HereSomext HereSome TText HereSome Text HereSome Text HereSome Text HereSome Text HereSome TText HereSome Text HereSome Text HereSome",
maxLines: 1,
),
),
)
],
),
),
Icon(Icons.arrow_forward),
],
);
Run Code Online (Sandbox Code Playgroud)
输出,长文本:
输出,短文本:
归档时间: |
|
查看次数: |
10527 次 |
最近记录: |