How to set max lines for Text or RichText?
Simple using the maxLines
property
Text("Some large text", maxLines: 2)
And you can use overflow: TextOverflow.ellipsis
to insert ...
overflow ellipsis in text
Text("Some large text", maxLines: 2, overflow: TextOverflow.ellipsis)
Edit 2021 - it's possible now
(Hint - Optional but recommended is to set some overflow with maxLines)
Text(
'My text',
maxLines: 4,
overflow: TextOverflow.ellipsis,
),
RichText(
text: TextSpan(children: ....),
maxLines: 4,
overflow: TextOverflow.ellipsis,
),
I believe it's supported now:
RichText(
maxLines: 2,
overflow: TextOverflow.ellipsis, // TextOverflow.clip // TextOverflow.fade
text: TextSpan(
text: 'Hello ',
style: DefaultTextStyle.of(context).style,
children: <TextSpan>[
TextSpan(text: 'bold', style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(text: ' world!'),
],
),
)