I\'m trying to get ExpansionTile
to collapse after I choose an item, but it does not close the list that was opened.
I tried to use the onExpansio
Create a clone from ExpansionTile class and replace build method code by the following:
@override
Widget build(BuildContext context) {
final bool closed = !_isExpanded && _controller.isDismissed;
return AnimatedBuilder(
animation: _controller.view,
builder: _buildChildren,
child: closed ? null : GestureDetector(
child: Column(children: widget.children),
onTap: _handleTap,
),
);
}
and then ExpansionTile will collapse after click on each item.
Note: if one of children has onTap call back, this solution doesn't work. in this case you must provide onChildTap handler to pass index of tapped child in use case.(contact me for complete code)