Dar*_*han 4 text widget overflow dart flutter
如何根据可用空间裁剪文本?
有一个类似的问题在这里,但没有工作的答案。
目前,此代码
return new GridTile(
child: new Card(
elevation: 3.0,
child: new Container(
padding: new EdgeInsets.all(10.0),
child: new Column(
children: <Widget>[
Text(
document['title'],
style: new TextStyle(fontWeight: FontWeight.bold),
),
Text(
document['text'],
),
],
),
),
)
);
Run Code Online (Sandbox Code Playgroud)
给出了这个结果:
我尝试使用overflow: TextOverflow.ellipsis,但文本变成 1 行长。指定文本行长度是一个坏主意,因为在不同的屏幕尺寸上结果会有所不同。
如何使文本裁剪、适合或包裹到可用空间中?
设置overflow
行为应该做
new Text(
widget.text,
// softWrap: true,
overflow: TextOverflow.fade,
)
Run Code Online (Sandbox Code Playgroud)
小智 5
将文本小部件包裹在“扩展”或“灵活”小部件内,并使用“overflow.ellipsis”,这对我有用
Column(
children: <Widget>[
Flexible(
child: Text(
"Some Very long Text or random generated strings ",
overflow: TextOverflow.ellipsis,
softWrap: true,
),
),
],
),
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5852 次 |
最近记录: |