我正在制作一个包含一些包含文本的图块的列表,但是它们不能足够大以至于会破坏布局。因此,我仅从文本中获取一个子字符串,然后在其中添加“ ...”,以指示布局中隐藏了更多文本。 问题是,某些文本处于大写锁定状态,这使文本具有不同的大小。 以下是图块的示例代码:
class _MessageTileState extends State<MessageTile> {
@override
Widget build(BuildContext context) {
final colorGrey = Theme.of(context).unselectedWidgetColor;
final screenSize = MediaQuery.of(context).size;
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
messageIcon(widget.message),
SizedBox(width: 16.0),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
widget.message.author.length > 38 ? widget.message.author.substring(0, 35) + '...' : widget.message.author,
style: TextStyle(
fontSize: screenSize.width * 0.033,
fontWeight: FontWeight.w600,
height: 1.6,
color: widget.message.read ? colorGrey : null,
),
),
Text(
widget.message.title.length > 38 ? widget.message.title.substring(0, 35) + '...' : widget.message.title,
style: TextStyle(
fontSize: screenSize.width * 0.033,
fontWeight: FontWeight.w600,
height: 1.6,
color: widget.message.read ? colorGrey : null,
),
),
Text(
widget.message.message.length > 38 ? widget.message.message.substring(0, 35).replaceAll('\n\n', ' ') + '...' : widget.message.message.replaceAll('\n\n', ' '),
style: TextStyle(
fontSize: screenSize.width * 0.033,
height: 1.6,
color: widget.message.read ? colorGrey : null,
),
),
Text(
DateFormat('MM/dd/yyyy - h:mm a').format(widget.message.date),
style: TextStyle(
fontSize: screenSize.width * 0.033,
fontWeight: FontWeight.w600,
color: colorGrey,
height: 1.6,
),
),
],
),
],
);
这是显示问题的图像:
我希望文本占用相同的空间,而不管是大写还是小写。 (对大写或小写进行简单检查不起作用,这是因为“在标题上存在类似THIS的文字”-大小写字母大小写不同)。
PS:等宽字体不起作用。
不要应用子字符串或任何东西。
Please try a
Text()
property calledoverflow
andmaxLines
Documentation for: TextOverflow enum