I want to disable the expandable icon if the number of lines is within the threshold limit.
I am using the ExpandablePanel
widget, but I am not able to figure out how to disable the icon.
Asked
Active
Viewed 365 times
1

Aayush Goyal
- 73
- 9
2 Answers
0
You can use a conditional operator in hasIcon to disable the icon
First get the number of lines your text takes up and then use a conditional operator to make the icon visible/invisible
final numLines = '\n'.allMatches(yourText).length + 1;
ExpandablePanel(
.
.
.
hasIcon: numLines > MAX_LINES? true: false,
)
Here MAX_LINES is the maximum number of lines you have set.
I hope this helps.

Arsh Shaikh
- 1,106
- 5
- 21
-
Oh, I'm sorry then. This was the only way I knew. – Arsh Shaikh Jan 17 '20 at 02:20
0
I calculated the number of lines using
final span = TextSpan(text: txt);
final tp = TextPainter(
text: span, textDirection: TextDirection.ltr, maxLines: 3);
tp.layout(maxWidth: size.maxWidth);
then I used hasIcon: tp.didExceedMaxLines ? true : false,
to enable/disable the icon.

Aayush Goyal
- 73
- 9