'How to add `overflow` to SelectableText in Flutter?
There is SelectableText
widget that allows you to make text selectable. But it misses the overflow
parameter, which is required...
Is there any workaround, which can make it work? Or a similar solution? Thanks!
Solution 1:[1]
Just experienced this.
The problem is overflow
hasn't been made the top level parameter in case of SelectableText
as with Text
in Flutter which suggests that it must be there, just not as the top level parameter which is true as it is in TextStyle
.
Hence, to use overflow
in SelectableText
, change
SelectableText(
text,
overflow: TextOverflow.ellipsis
)
to
SelectableText(
text,
style: TextStyle(
overflow: TextOverflow.ellipsis,
),
)
Solution 2:[2]
In my case above solutions didn't work.
I found another solution using ListTile
:
ListTile(
title: SelectableText(
text,
toolbarOptions: const ToolbarOptions(
copy: true,
selectAll: true,
cut: true,
),
),
)
and it worked as overflow: TextOverflow.ellipsis
for me
Solution 3:[3]
If the TextOverflow.clip effect is enough for you this did the trick for me:
SelectableText("My text"
maxLines: 1,
scrollPhysics: NeverScrollableScrollPhysics())
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Lalit Fauzdar |
Solution 2 | Abduboriy Jonmirzayev |
Solution 3 | Andres Sosa Martinez |