[英]How to handle right overflowed inside ListTile flutter
I have listTile to show title and subtitle... here is the code我有 listTile 来显示标题和副标题......这是代码
ListTile(
leading: InkWell(
onTap: () {},
child: Icon(Icons.fingerprint),
),
title: Text("name xxx"),
subtitle:
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
"xxxxxxxx",
),
Text(
' - ',
style: TextStyle(
fontSize: 10.0,
),
),
Text(
"yyyyyyyyyy",
style: TextStyle(
fontSize: 10.0,
),
),
],
),
],
),
trailing: ...
)
when I replace xxxxxx
and yyyyyyy
with long sentences... I got right overflowed by 69 pixels
so, is there a way to show my long subtitle and to prevent this problem当right overflowed by 69 pixels
用长句替换xxxxxx
和yyyyyyy
...
You have lots of potential solutions to your problem, i can suggest you two simple options:你的问题有很多潜在的解决方案,我可以建议你两个简单的选择:
If you absolutely need to show all the content of the two Text widget, you can wrap them inside a Wrap
, rather than in a Row
:如果您绝对需要显示两个 Text 小部件的所有内容,则可以将它们包装在Wrap
中,而不是Row
中:
ListTile(
leading: InkWell(
onTap: () {},
child: Icon(Icons.fingerprint),
),
title: Text("name xxx"),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Wrap(
children: [
Text(
"long text yeah long text long long and very long",
),
Text(
' - ',
style: TextStyle(
fontSize: 10.0,
),
),
Text(
"Another quite long stuff, it's veeery long and by no means short",
style: TextStyle(
fontSize: 10.0,
),
),
],
),
],
),
),
If you need your Row, with all its children, to stay within a single line of text, you can wrap your Text widgets with a Flexible
and instruct them to handle a potential overflow (maybe with an ellipsis):如果您需要您的 Row 及其所有子项保持在一行文本中,您可以使用Flexible
包装您的 Text 小部件并指示它们处理潜在的溢出(可能使用省略号):
ListTile(
leading: InkWell(
onTap: () {},
child: Icon(Icons.fingerprint),
),
title: Text("name xxx"),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Flexible(
child: Text(
"long text yeah long text long long and very long",
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
Text(
' - ',
style: TextStyle(
fontSize: 10.0,
),
),
Flexible(
child: Text(
"Another quite long stuff, it's veeery long and by no means short",
style: TextStyle(
fontSize: 10.0,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
),
],
),
),
Wrap the Text
widget with an Expanded
widget:用Expanded
小部件包装Text
小部件:
children: [
const Expanded(child:
Text(
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
textAlign: TextAlign.justify,
overflow: TextOverflow.ellipsis,
),
),
Text(
' - ',
style: TextStyle(
fontSize: 10.0,
),
),
const Expanded(child:
Text(
"yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
textAlign: TextAlign.justify,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 10.0,
),
),
),
],
https://api.flutter.dev/flutter/widgets/Expanded-class.html https://api.flutter.dev/flutter/widgets/Expanded-class.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.