我需要在中间截断overflow.ellipsis
文本,在最后始终显示id文本,如下所示
Really, Really Long
Compa... ID 0000001
我试着用RichText
这样做
valueWidget: RichText(
maxLines: 2,
overflow: TextOverflow.ellipsis,
text: TextSpan(
children: [
TextSpan(
text: '${organisation.displayName} Really, '
'Really Long Company Name',
style: theme
.textTheme(textColor: theme.secondary.defaultColor.value)
.headline5?.copyWith(overflow: TextOverflow.ellipsis),
),
TextSpan(
text: ' GB ${organisation.id}',
style: theme
.textTheme(textColor: theme.neutral.dark1Color.value)
.headline5?.copyWith(overflow: TextOverflow.visible),
)
],
),
),
但是它没有像我期望那样工作。2我怎样才能做好呢?
1条答案
按热度按时间l7wslrjt1#
You can use a
Row
widget with the company name part wrapped into anExpanded
widget. This way the id will be displayed completely, and the rest of the available space will be occupied by the name. If the name is longer than the remaining space, it will end with the ellipsis.(If the total space available is not enough for the id, you will get an error.)
For example see this
SizedBox
: