I have a long String inside a Text Widget. I have placed the widget inside a SizedBox widget with some fixed width, and I have given the Text Widget a maxLines of 4. Is there a way to get the length of the displayed string? I.e., I want to get the number of characters that were displayed on the screen, before TextOverflow was used.
2
Answers
You can use the
TextPainter
for this, it allows you to get paint separately a text, and it is responsible for painting theText
widget :and now that you got that
indexOfOverflowing
where the text starts overflowing, you can simplysubstring
it like this:and you can use now the
limitedText
.