Skip to content

Commit 865578c

Browse files
committed
feat: ExpansionPanel
1 parent e5d49e9 commit 865578c

File tree

5 files changed

+157
-0
lines changed

5 files changed

+157
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## **ExpansionPanel**
2+
3+
>
4+
扩展面板,包含一个标题和一个正文,可以展开或折叠,面板正文在展开时可见
5+
* ExpansionPanel不能单独使用,只能配合ExpansionPanelList使用
6+
* ExpansionPanelList必须配合可以滑动的组件才可以使用
7+
8+
### ExpansionPanelList构造方法
9+
``` dart
10+
ExpansionPanelList({
11+
Key key,
12+
this.children = const <ExpansionPanel>[],
13+
this.expansionCallback,
14+
this.animationDuration = kThemeAnimationDuration,
15+
})
16+
```
17+
18+
### ExpansionPanel构造方法
19+
``` dart
20+
ExpansionPanel({
21+
@required this.headerBuilder,
22+
@required this.body,
23+
this.isExpanded = false
24+
})
25+
```
26+
27+
### ExpansionPanelList属性介绍
28+
* children:ExpansionPanel内容
29+
* expansionCallback:点击展开关闭面板回调函数
30+
* animationDuration:展开面板时间
31+
32+
### ExpansionPanel属性介绍
33+
* headerBuilder:标题构造器
34+
* body:内容区域
35+
* isExpanded:是否展开
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import 'package:flutter/material.dart';
2+
3+
class ExpansionPanelItem {
4+
final String headerText;
5+
final Widget body;
6+
bool isExpanded;
7+
ExpansionPanelItem({
8+
this.headerText,
9+
this.body,
10+
this.isExpanded
11+
});
12+
}
13+
14+
class Index extends StatefulWidget {
15+
@override
16+
_IndexState createState() => _IndexState();
17+
}
18+
19+
class _IndexState extends State<Index> {
20+
List<ExpansionPanelItem> _expansionPanelItems;
21+
@override
22+
void initState() {
23+
// TODO: implement initState
24+
super.initState();
25+
_expansionPanelItems = <ExpansionPanelItem>[
26+
ExpansionPanelItem(
27+
headerText: 'Panel A',
28+
body: Container(
29+
padding: EdgeInsets.all(16.0),
30+
width: double.infinity,
31+
child: Image.network('http://pic1.win4000.com/wallpaper/2019-02-15/5c664c46823f8.jpg'),
32+
),
33+
isExpanded: false
34+
),
35+
ExpansionPanelItem(
36+
headerText: 'Panel B',
37+
body: Container(
38+
padding: EdgeInsets.all(16.0),
39+
width: double.infinity,
40+
child: Image.network('http://pic1.win4000.com/wallpaper/2019-02-14/5c651084373de.jpg'),
41+
),
42+
isExpanded: false
43+
),
44+
ExpansionPanelItem(
45+
headerText: 'Panel C',
46+
body: Container(
47+
padding: EdgeInsets.all(16.0),
48+
width: double.infinity,
49+
child: Image.network('http://pic1.win4000.com/wallpaper/2019-02-14/5c65107a0ee05.jpg'),
50+
),
51+
isExpanded: false
52+
)
53+
];
54+
55+
}
56+
@override
57+
Widget build(BuildContext context) {
58+
return Scaffold(
59+
appBar: AppBar(title: Text('ExpansionPanel'),),
60+
body: SingleChildScrollView(
61+
padding: EdgeInsets.all(16.0),
62+
child: ExpansionPanelList(
63+
animationDuration: Duration(microseconds: 500),
64+
expansionCallback: (int panelIndex, bool isExpaned) {
65+
setState(() {
66+
_expansionPanelItems[panelIndex].isExpanded = !isExpaned;
67+
});
68+
},
69+
children: _expansionPanelItems.map(
70+
(ExpansionPanelItem item) {
71+
return ExpansionPanel(
72+
isExpanded: item.isExpanded,
73+
body: item.body,
74+
headerBuilder: (BuildContext context, bool isExpanded) {
75+
return Container(
76+
padding: EdgeInsets.all(16.0),
77+
child: Text(
78+
item.headerText,
79+
style: Theme.of(context).textTheme.title,
80+
),
81+
);
82+
}
83+
);
84+
}
85+
).toList(),
86+
),
87+
),
88+
);
89+
}
90+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:efox_flutter/components/widgetComp.dart' as WidgetComp;
3+
import 'demo.dart' as Demo;
4+
5+
class Index extends StatefulWidget {
6+
static String title = 'ExpansionPanel';
7+
static String originCodeUrl = 'https://docs.flutter.io/flutter/material/ExpansionPanel-class.html';
8+
static String mdUrl = 'docs/widget/bulletbox/expansionpanel/index.md';
9+
@override
10+
_IndexState createState() => _IndexState();
11+
}
12+
13+
class _IndexState extends State<Index> {
14+
@override
15+
Widget build(BuildContext context) {
16+
return WidgetComp.Index(
17+
title: Index.title,
18+
originCodeUrl: Index.originCodeUrl,
19+
mdUrl: Index.mdUrl,
20+
demoChild: <Widget>[
21+
Demo.Index()
22+
],
23+
);
24+
}
25+
}

lib/widget/bulletbox/index.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'simpledialog/index.dart' as SimpleDialog;
33
import 'alertdialog/index.dart' as AlertDialog;
44
import 'bottomsheet/index.dart' as BottomSheet;
55
import 'snackbar/index.dart' as SnackBar;
6+
import 'expansionPanel/index.dart' as ExpansionPanel;
67

78
const nameSpaces = '/bulletbox_';
89

@@ -26,6 +27,11 @@ List widgets = [
2627
widget: SnackBar.Index(),
2728
code: 59670, // date_range
2829
title: SnackBar.Index.title
30+
),
31+
ItemInfo(
32+
widget: ExpansionPanel.Index(),
33+
code: 59651, // event_seat
34+
title: ExpansionPanel.Index.title
2935
)
3036
];
3137

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ flutter:
8484
- docs/widget/bulletbox/alertdialog/
8585
- docs/widget/bulletbox/bottomsheet/
8686
- docs/widget/bulletbox/snackbar/
87+
- docs/widget/bulletbox/expansionpanel/
8788
- docs/widget/navigator/appbar/
8889
- docs/widget/navigator/scaffold/
8990
# An image asset can refer to one or more resolution-specific "variants", see

0 commit comments

Comments
 (0)