ExpansionTile force closes once it detects a scrolling behavior i.e immediately I scroll the page... I want to keep the ExpansionTile opened until I tapped on its title.
What could be the cause?
Add and remove indices from a list with onExpansionChanged
callback and set initiallyExpanded
if it contains that index.
class _WidgetState extends State<Widget> {
List expandedIndices = [];
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
physics: const BouncingScrollPhysics(
parent: AlwaysScrollableScrollPhysics()),
itemCount: 10,
itemBuilder: (BuildContext context, int index) {
return ExpansionTile(
title: Text('Item'),
onExpansionChanged: (expanded) {
if(expanded) {
expandedIndices.add(index);
}
else{
expandedIndices.remove(index);
}
},
initiallyExpanded: expandedIndices.contains(index),);
}
)
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With