What is the equivalent of onExpansionChanged for Flutter ExpandablePanel
Use an ExpandableController
and an ExpandableNotifier
:
class MyWidget extends StatefulWidget {
const MyWidget({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _MyWidget();
}
class _MyWidget extends State<MyWidget> {
final ExpandableController expandableController = ExpandableController();
void onExpandableControllerStateChanged() {
if (expandableController.expanded) {
// Do your stuff when panel got expanded here
} else {
// Do your stuff when panel got collapsed here
}
}
@override
void initState() {
super.initState();
expandableController.addListener(onExpandableControllerStateChanged);
}
@override
void dispose() {
expandableController.removeListener(onExpandableControllerStateChanged);
super.dispose();
}
@override
Widget build(BuildContext context) {
return ExpandableNotifier(
controller: expandableController,
child: ExpandablePanel(
header: HeaderWidget(),
collapsed: CollapsedWidget(),
expanded: ExpandedWidget(),
),
);
}
}