Flutter ExpansionPanelList.radio widget is excellent for showing and hiding panel and it’s description. With ExpansionPanelList.radio, we can make sure if you tap on a new panel, the older one close automatically.
ExpansionPanelList.radio internally could use ExpansionPanelRadio() widget to show more items.
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
List myList=[
'laravel',
'flutter',
'goLang'
];
final List<Map<String, dynamic>> _items = List.generate(
20,
(index) => {
'id': index,
'title': 'Item $index',
'description':
'This is the description of the item $index. There is nothing important here. In fact, it is meaningless.',
});
return Scaffold(
appBar: AppBar(title: Text("Expand"),),
body: SingleChildScrollView(
child: ExpansionPanelList.radio(
children: _items.map((e) => ExpansionPanelRadio(
value: e['id'],
headerBuilder: (BuildContext context, bool isExpanded)=>ListTile(
title: Text(e['title'].toString()),
),
body: Container(
child: Text(
e['description']
),
)
)).toList(),
),
),
);
}
}
ExpansionPanelList.radio() could be suitable for complex JSON or Map data structure.