1

Sample Screenshot

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.

2 Answers2

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
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.