53 lines
1.2 KiB
Dart
53 lines
1.2 KiB
Dart
|
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<ExpandableListItem> entries;
|
||
|
|
||
|
const ExpandableList(this.entries, {super.key});
|
||
|
|
||
|
@override
|
||
|
State<ExpandableList> createState() => _ExpandableListState();
|
||
|
}
|
||
|
|
||
|
class _ExpandableListState extends State<ExpandableList> {
|
||
|
@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<ExpansionPanel>((ExpandableListItem item) {
|
||
|
return ExpansionPanel(
|
||
|
headerBuilder: (BuildContext context, bool isExpanded) {
|
||
|
return item.header;
|
||
|
},
|
||
|
body: item.body,
|
||
|
isExpanded: item.isExpanded,
|
||
|
);
|
||
|
}).toList(),
|
||
|
);
|
||
|
}
|
||
|
}
|