I have a question about flutter text overflow.
When I set maxLines: 1, overflow: TextOverflow.ellipsis,
I have a issue that in case if second(or each other word except first one) word is large word, it will be replaced with 3 dot at all.
So
In case it I have text "Some laaaaaaaaaaarge text" I will have result like:
Screen Start|Some ... | Screen end
I want to have something like:
Screen Start|Some laaaaaaaa...| Screen end
Also I maxLines: 1, softWrap: true, overflow: TextOverflow.ellipsis,
but it doesn’t helps
3
Answers
Try to put your Text Widget inside a Sized container.
Like this.
Output:
I was having the same issue and it seems like this behaviour of
TextOverflow.ellipsis
is by design as mentioned here: https://github.com/flutter/flutter/issues/18761#issuecomment-514413734I found this solution which uses a custom
EllipsizedText
widget and seems to work quite nicely*: https://itnext.io/writing-custom-widgets-in-flutter-part-1-ellipsizedtext-a0efdc1368a8Direct link to the implementation of
EllipsizedText
on GitHub:https://github.com/MatrixDev/Flutter-CustomWidgets/blob/main/lib/part1_ellipsized_text/ellipsized_text.dart
* Apparently it can’t use a
DefaultTextStyle
as is. I fixed this by addingto
RenderEllipsizedText
, and changing_layoutText()
toNow I just changed
createRenderObject()
toto grab the
DefaultTextStyle
.