我正在从db加载数据。有时我会得到更长的字符串,这会导致文本溢出。如何使溢出文本转到下一行?
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)),
],
),
),
],
),
),
);发布于 2020-11-25 22:28:26
您需要将Column包装在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'),
],
),
),
],
)发布于 2020-11-25 22:30:48
尝试将文本换行为灵活的
Flexible(
child: Text('Some lengthy text for testing'),
)发布于 2020-11-26 14:05:39
您需要使用overFlow在文本小部件中添加maxLine。
Text('long text here',
textAlign: TextAlign.center,
style: TextStyle(
color:
AppColors.subHeadingColor,
fontFamily: 'Rubik',
fontWeight:
FontConstants.rubikMedium),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),https://stackoverflow.com/questions/65006521
复制相似问题