-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathexpansion_panel_demo.dart
92 lines (85 loc) · 2.45 KB
/
expansion_panel_demo.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import 'package:flutter/material.dart';
class ExpansionPanelItem {
final String heartText;
final Widget body;
bool isExpanded;
ExpansionPanelItem({
this.heartText,
this.body,
this.isExpanded,
});
}
class ExpansionPanelDemo extends StatefulWidget {
@override
_ExpansionPanelDemoState createState() => _ExpansionPanelDemoState();
}
class _ExpansionPanelDemoState extends State<ExpansionPanelDemo> {
List<ExpansionPanelItem> _expansionPanelItem;
@override
void initState() {
super.initState();
_expansionPanelItem = <ExpansionPanelItem>[
ExpansionPanelItem(
heartText: 'Panel A',
body: Container(
padding: EdgeInsets.all(16.0),
width: double.infinity,
child: Text('Content for Panel A'),
),
isExpanded: false,
),
ExpansionPanelItem(
heartText: 'Panel B',
body: Container(
padding: EdgeInsets.all(16.0),
width: double.infinity,
child: Text('Content for Panel B'),
),
isExpanded: false,
),
ExpansionPanelItem(
heartText: 'Panel C',
body: Container(
padding: EdgeInsets.all(16.0),
width: double.infinity,
child: Text('Content for Panel C'),
),
isExpanded: false,
),
];
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('ExpansionPanelDemo'),
elevation: 0.0,
),
body: Container(
padding: EdgeInsets.all(18.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ExpansionPanelList(
expansionCallback: (int panelIndex, bool isExpanded) =>
setState(() {
_expansionPanelItem[panelIndex].isExpanded = !isExpanded;
}),
children: _expansionPanelItem.map((ExpansionPanelItem item) {
return ExpansionPanel(
body: item.body,
isExpanded: item.isExpanded,
headerBuilder: (BuildContext context, bool isExpanded) =>
Container(
padding: EdgeInsets.all(16.0),
child: Text(item.heartText, style: Theme.of(context).textTheme.headline6),
),
);
}).toList(),
),
],
),
),
);
}
}