我希望随着文本的增长自动换行。我搜索了一下,几乎所有的东西都尝试了 Package ,但文本仍然停留在一行,从屏幕上溢出。有人知道如何实现这一点吗?任何帮助是高度赞赏!
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,
),
),
));
9条答案
按热度按时间6psbrbz91#
Flexible
可以实现这一点这是https://flutter.dev/docs/development/ui/layout#lay-out-multiple-widgets-vertically-and-horizontally关于如何安排小部件的官方文档www.example.com。
请记住,
Flexible
和Expanded
应该只在Column
,Row
或Flex
中使用,因为Incorrect use of ParentDataWidget
。解决方案不仅仅是
Flexible
vddsk6oq2#
在我的一个项目中,我将
Text
示例 Package 在Container
s周围。这个特殊的代码示例提供了两个堆叠的Text对象。下面是一个代码示例。
[编辑]为容器添加了宽度约束
xggvc2p63#
使用省略号
使用淡入淡出
注:
如果您在
Row
中使用Text
,则可以将Text
置于Expanded
中,如下所示:nfeuvbwi4#
使用扩展
1l5u6lss5#
如果是要 Package 的单个文本widget,可以使用Flexible或Expandedwidget。
或
对于多个widget,您可以选择Wrapwidget。更多详情请查看this
inn6fuwd6#
尝试
Wrap
小部件在文本增长时换行:示例:
xqk2d5yq7#
你可以用Flexible Widget Package 你的小部件,然后你可以使用Text Widget的溢出属性设置Text的属性。你必须设置TextOverflow.clip,例如:-
希望这对某人有帮助:)
9wbgstp78#
fjaof16o9#
您可以使用Flexible,在这种情况下,person.name可以是一个长名称(Labels和BlankSpace是返回widget的自定义类):