import 'package:flutter/material.dart'; class ExpandableListItem { ExpandableListItem({ required this.body, required this.header, this.isExpanded = false, }); Widget body; Widget header; bool isExpanded; } class ExpandableList extends StatefulWidget { final List entries; const ExpandableList(this.entries, {super.key}); @override State createState() => _ExpandableListState(); } class _ExpandableListState extends State { @override Widget build(BuildContext context) { return SingleChildScrollView( child: Container( child: _buildPanel(), ), ); } Widget _buildPanel() { return ExpansionPanelList( expansionCallback: (int index, bool isExpanded) { setState(() { widget.entries[index].isExpanded = isExpanded; }); }, children: widget.entries.map((ExpandableListItem item) { return ExpansionPanel( headerBuilder: (BuildContext context, bool isExpanded) { return ListTile( title: item.header, onTap: () { setState(() { widget.entries.firstWhere((x) => x == item).isExpanded = !isExpanded; }); }, ); }, body: item.body, isExpanded: item.isExpanded, ); }).toList(), ); } }