随着文本的增长,我想要包装文本.我搜索并尝试用几乎所有东西包裹,但仍然文本保持一行并从屏幕溢出.有谁知道如何实现这一目标?任何帮助都非常感谢!
Positioned(
left: position.dx,
top: position.dy,
child: new Draggable(
data: widget.index,
onDragStarted: widget.setDragging,
onDraggableCanceled: (velocity, offset) {
setState(() {
position = offset;
widget.secondCallback(offset, widget.index);
widget.endDragging();
});
},
child: new GestureDetector(
onTap: () {
widget.callback(widget.caption, widget.index);
},
child: new Text(
widget.caption.caption,
style: new TextStyle(
color: widget.caption.color,
fontSize: widget.caption.fontSize,
),
),
),
feedback: new Material(
type: MaterialType.transparency,
child: new Text(
widget.caption.caption,
style: new TextStyle(
color: widget.caption.color,
fontSize: widget.caption.fontSize),
softWrap: true,
),
),
));
Run Code Online (Sandbox Code Playgroud)
Cop*_*oad 66
使用省略号
Text(
"This is a long text",
overflow: TextOverflow.ellipsis,
),
Run Code Online (Sandbox Code Playgroud)
使用淡入淡出
Text(
"This is a long text",
overflow: TextOverflow.fade,
maxLines: 1,
softWrap: false,
),
Run Code Online (Sandbox Code Playgroud)
使用剪辑
Text(
"This is a long text",
overflow: TextOverflow.clip,
maxLines: 1,
softWrap: false,
),
Run Code Online (Sandbox Code Playgroud)
笔记:
如果您Text在 a中使用Row,则可以将上面的内容Text放在里面,Expanded例如:
Expanded(
child: AboveText(),
)
Run Code Online (Sandbox Code Playgroud)
Pio*_*ura 38
使用扩展
Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text(_name, style: Theme.of(context).textTheme.subhead),
new Container(
margin: const EdgeInsets.only(top: 5.0),
child: new Text(text),
),
],
),
Run Code Online (Sandbox Code Playgroud)
小智 36
这对我有用
new Container(
child: Row(
children: <Widget>[
Flexible(
child: new Text("A looooooooooooooooooong text"))
],
));
Run Code Online (Sandbox Code Playgroud)
没有容器的宽度,Flexible会包装文本。
Max*_*ini 28
在我的一个项目中,我将Text实例包装在Containers 周围.此特定代码示例具有两个堆叠的Text对象.
这是一个代码示例.
//80% of screen width
double c_width = MediaQuery.of(context).size.width*0.8;
return new Container (
padding: const EdgeInsets.all(16.0),
width: c_width,
child: new Column (
children: <Widget>[
new Text ("Long text 1 Long text 1 Long text 1 Long text 1 Long text 1 Long text 1 Long text 1 Long text 1 Long text 1 Long text 1 Long text 1 Long text 1 Long text 1 Long text 1 ", textAlign: TextAlign.left),
new Text ("Long Text 2, Long Text 2, Long Text 2, Long Text 2, Long Text 2, Long Text 2, Long Text 2, Long Text 2, Long Text 2, Long Text 2, Long Text 2", textAlign: TextAlign.left),
],
),
);
Run Code Online (Sandbox Code Playgroud)
[edit]为容器添加了宽度约束
KPa*_*ian 19
如果您要包装的是单个文本小部件,则可以使用“ 灵活”或“ 扩展”小部件。
Expanded(
child: Text('Some lengthy text for testing'),
)
Run Code Online (Sandbox Code Playgroud)
要么
Flexible(
child: Text('Some lengthy text for testing'),
)
Run Code Online (Sandbox Code Playgroud)
对于多个小部件,您可以选择包装小部件。有关更多详细信息,请查看此
小智 16
尝试Wrap小部件随着文本的增长来包装文本:
例子:
Wrap(
direction: Axis.vertical, //Vertical || Horizontal
children: <Widget>[
Text(
'Your Text',
style: TextStyle(fontSize: 30),
),
Text(
'Your Text',
style: TextStyle(fontSize: 30),
),
],
),
Run Code Online (Sandbox Code Playgroud)
Vai*_*ala 11
您可以使用 Flexible Widget 包装您的小部件,然后您可以使用 Text Widget 的溢出属性设置 Text 的属性。你必须设置TextOverflow。剪辑 例如:-
Flexible
(child: new Text("This is Dummy Long Text",
style: TextStyle(
fontFamily: "Roboto",
color: Colors.black,
fontSize: 10.0,
fontWeight: FontWeight.bold),
overflow: TextOverflow.clip,),)
Run Code Online (Sandbox Code Playgroud)
希望这有助于某人:)
小智 7
Container(
color: Color.fromRGBO(224, 251, 253, 1.0),
child: ListTile(
dense: true,
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
RichText(
textAlign: TextAlign.left,
softWrap: true,
text: TextSpan(children: <TextSpan>
[
TextSpan(text: "hello: ",
style: TextStyle(
color: Colors.black, fontWeight: FontWeight.bold)),
TextSpan(text: "I hope this helps",
style: TextStyle(color: Colors.black)),
]
),
),
],
),
),
),
Run Code Online (Sandbox Code Playgroud)
您可以使用灵活,在这种情况下,person.name可以是一个长名称(Labels 和 BlankSpace 是返回小部件的自定义类):
new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
new Flexible(
child: Labels.getTitle_2(person.name,
color: StyleColors.COLOR_BLACK)),
BlankSpace.column(3),
Labels.getTitle_1(person.likes())
]),
BlankSpace.row(3),
Labels.getTitle_2(person.shortDescription),
],
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
48947 次 |
| 最近记录: |