How do I make it so that the icon will only update for the tile that was clicked? Right now, the behavior is that all icons update when clicking on one tile.
Here is the code (trimmed to only include relevant parts):
Column(children: List.generate(
filteredFAQ.length,
(index) => Column(
children: [
if(index > 0) {
Container(
child: Column(
children: <Widget>[
ExpansionTile(
trailing: SvgPicture.string(
isQuestionClicked
? addPayeeArrowUp
: rightArrow,
color: primary,
),
onExpansionChanged:
(bool expanded) {
setState(() {
isQuestionClicked = expanded;
});
},
),
],
)
)
}
]
)
),);
here are screenshots of the behavior:
[2I used the in built onExpansionChange of the ExpansionTile.
2
Answers
You have to manage each childrens state separatory.
I think it’s best to manage them in filteredFAQ by adding
property there. but you can achive by manage them as separated property like
and change their state when they’re expanded
here’s a sample complete code
And don’t forget to initalize items at where you initialize filteredFAQ
If you provide a whole code in the widget I can complete it if you need more information
To only change the icon of the expanded tile, you can use this approach:
create a
Map
:and use it accordingly in your
ExpansionTile
to check whether it’s selected, if the value istrue
orfalse
:Complete runnable example: