Flutter 防止文本在颤振中溢出
我正在从数据库加载数据。有时我得到更长的字符串,这会导致文本溢出。如何使溢出的文本转到下一行Flutter 防止文本在颤振中溢出,flutter,flutter-layout,Flutter,Flutter Layout,我正在从数据库加载数据。有时我得到更长的字符串,这会导致文本溢出。如何使溢出的文本转到下一行 Padding( padding: const EdgeInsets.all(5), child: Card( color: (list[index]['author'] == widget.user.email) ? Colors.greenAccent : Colors.grey[900],
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)),
],
),
),
],
),
),
);
填充(
填充:常量边集。全部(5),
孩子:卡片(
颜色:(列表[index]['author']==widget.user.email)?Colors.greenAccent:Colors.grey[900],
孩子:排(
mainAxisAlignment:mainAxisAlignment.start,
儿童:[
圆形(
半径:40,
背景图片:NetworkImage(列表[索引]['profilePicUrl']),
),
填充物(
填充:仅限常量边集(左:60),
子:列(
儿童:[
Text(list[index]['message'],softWrap:false,overflow:textfoverflow.clip,style:TextStyle(颜色:(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)),
],
),
),
],
),
),
);
您需要将列
包装在展开的
中,以下是小部件树的示例代码:
行(
mainAxisAlignment:mainAxisAlignment.start,
儿童:[
展开(//尝试将文本以灵活的格式包装
Flexible(
child: Text('Some lengthy text for testing'),
)
您需要在带有溢出的文本小部件中添加maxLine
Text('long text here',
textAlign: TextAlign.center,
style: TextStyle(
color:
AppColors.subHeadingColor,
fontFamily: 'Rubik',
fontWeight:
FontConstants.rubikMedium),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
从您的代码中,我可以理解您正在使用填充
小部件将消息
和作者
属性包装在文本
小部件中
填充
小部件位于另一个行
小部件内部。默认情况下,一行或一列沿其主轴占据尽可能多的空间。因此,在大小固定的循环器
之后,子项将占据行
小部件中剩余的几乎全部空间
整个代码(Padding
小部件在CircularAvatar
之后)可以
包装在扩展的中,这将帮助您防止
像素溢出错误,并将softwrap:true
属性添加到Text
小部件,它将使消息显示在下一个连续窗口中
台词
这是我尝试过的代码的最低版本
Padding(
padding: const EdgeInsets.all(5),
child: Card(
color: Colors.greenAccent,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
CircleAvatar(
radius: 40,
backgroundImage: NetworkImage('profilePicUrl'),
),
//Wrapped inside the Expanded.
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 60),
child: Column(
children: <Widget>[
Text(
'messagemessagemessagemessagemessagemessagemessagemessagemessage12345678',
softWrap: true, // Set softwrap to true to make it to next line
style: TextStyle(color: Colors.white, fontSize: 20)),
Text('author',
style: TextStyle(color: Colors.grey, fontSize: 15)),
],
),
),
)
],
),
),
);
填充(
填充:常量边集。全部(5),
孩子:卡片(
颜色:Colors.greenAccent,
孩子:排(
mainAxisAlignment:mainAxisAlignment.start,
儿童:[
圆形(
半径:40,
背景图像:NetworkImage('profilePicUrl'),
),
//包裹在展开的容器内。
扩大(
孩子:填充(
填充:仅限常量边集(左:60),
子:列(
儿童:[
正文(
'Message12345678',
softWrap:true,//将softWrap设置为true,使其成为下一行
样式:TextStyle(颜色:Colors.white,fontSize:20)),
文本('作者',
样式:TextStyle(颜色:Colors.grey,fontSize:15)),
],
),
),
)
],
),
),
);
如果有用,请告诉我!!干杯
更新:
您仍然需要溢出
@PETKOMihalik请发布您面临的错误的最小代码。修复了吗?@petk