flutter - 防止文本在颤动中溢出
问题描述
我正在从数据库加载数据。有时我会得到更长的字符串,这会导致文本溢出。如何使溢出的文本转到下一行?
Padding(
padding: const EdgeInsets.all(5),
child: Card(
color: (list[index]['author'] == widget.user.email) ? Colors.greenAccent : Colors.grey[900],
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
CircleAvatar(
radius: 40,
backgroundImage: NetworkImage(list[index]['profilePicUrl']),
),
Padding(
padding: const EdgeInsets.only(left: 60),
child: Column(
children: <Widget>[
Text(list[index]['message'],softWrap: false, overflow: TextOverflow.clip, style: TextStyle(color: (list[index]['author'] == widget.user.email) ? Colors.black : Colors.white, fontSize: 20)),
Text(list[index]['author'], style: TextStyle(color: (list[index]['author'] == widget.user.email) ? Colors.grey[800] : Colors.grey, fontSize: 15)),
],
),
),
],
),
),
);
解决方案
您需要将您的Column
in包装起来Expanded
,这是您的小部件树的示例代码:
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded( // <-- This is what you need
child: Column(
children: <Widget>[
Text(
'This is very long line which can overflow on small screen devices easily',
softWrap: false,
overflow: TextOverflow.ellipsis,
),
Text('author'),
],
),
),
],
)
推荐阅读
- javascript - 使用 Google API 自动完成电子邮件地址
- oracle-apex - 访问通过 APEX_ITEM.SELECT_LIST 创建的页面上的项目
- django - 如何在 Django 列表中添加序列号?
- c# - UWP 应用程序的 Azure 服务总线
- spring - 使用 Spring 和 Hibernate 4.3.5 无法正确打印 JSON
- python - 为什么 eval 尝试在 __builtins__ 上下标?
- php - empty() 在 PHP 中使用 isset() 吗?
- c# - 如何使用asp.net从布局视图发布表单?
- apache-spark - 火花铲斗
- django - Gunicorn 访问日志显示空用户