Easy and quick guide to implement the Expansion Panel List in Flutter.
You must have seen this interaction in many of the apps.
Expansion panel list is a list that shows its children using expansion animation on click of item.
ExpansionPanelList(
expansionCallback: (int index, bool isExpanded) {},
children: [
ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: Text('Item 1'),
);
},
body: ListTile(
title: Text('Item 1 child'),
subtitle: Text('Details goes here'),
),
isExpanded: true,
),
ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: Text('Item 2'),
);
},
body: ListTile(
title: Text('Item 2 child'),
subtitle: Text('Details goes here'),
),
isExpanded: false,
),
],
);
➊ expansionCallBack:
This gets called whenever the expand/collapsed button is pressed on any of the items inside the list.
It gives us two things.
➋ children:
ExpansionPanel widget is used as a child for the ExpansionPanelList. This widget has got below properties.
➌ animationDuration:
Used to define the duration in which the expand and collapsed animation should complete. It defaults to 200ms.
However, it is recommended to keep it to the original you can still change it to anything like this.
animationDuration: Duration(milliseconds: 300),
#flutter #mobile-apps #developer