Flutter Widget之ExpansionPanelList

Widget:https://flutter.io/docs/development/ui/widgets
ExpansionPanelList:https://docs.flutter.io/flutter/material/ExpansionPanelList-class.html
ExpansionPanel:https://docs.flutter.io/flutter/material/ExpansionPanel-class.html

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
93
94
import 'package:flutter/material.dart';

class ExpansionPanelListDemoPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new _ExpansionPanelListDemoPageState();
}
}

class _ExpansionPanelListDemoPageState extends State<ExpansionPanelListDemoPage> {
var currentPanelIndex = -1; //设置-1默认全部闭合
List<int> mList;

_ExpansionPanelListDemoPageState() {
mList = new List();
for (int i = 0; i < 3; i++) {
mList.add(i);
}
}

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
title: Text('ExpansionPanelList Demo'),
),
body: new SingleChildScrollView(
child: new Column(
children: <Widget>[
// new Text('默认样式'),
// new ExpansionPanelList(
// expansionCallback: (panelIndex, isExpanded) {
// setState(() {
// currentPanelIndex = (currentPanelIndex != panelIndex ? panelIndex : -1);
// });
// },
// children: mList.map((i) {
// return new ExpansionPanel(
// headerBuilder: (context, isExpanded) {
// return new ListTile(
// title: new Text('这是标题$i'),
// );
// },
// body: new Padding(
// padding: EdgeInsets.all(30.0),
// child: new ListBody(
// children: <Widget>[
// new Text('这是标题$i的内容'),
// ],
// ),
// ),
// isExpanded: currentPanelIndex == i,
// );
// }).toList(),
// ),

new Text('自定义样式'),
new ExpansionPanelList(
expansionCallback: (panelIndex, isExpanded) {
setState(() {
currentPanelIndex = (currentPanelIndex != panelIndex ? panelIndex : -1);
});
},
children: mList.map((i) {
return new ExpansionPanel(
headerBuilder: (context, isExpanded) {
return new ListTile(
title: new Text('这是标题$i'),
);
},
body: new Padding(
padding: EdgeInsets.all(30.0),
child: new ListView.builder(
itemCount: 1,
shrinkWrap: true, //必须设置
itemBuilder: (BuildContext context, int index) {
return new ListTile(
leading: new Icon(Icons.add),
title: new Text('这是标题$i的内容'),
);
},
),
),
isExpanded: currentPanelIndex == i,
);
}).toList(),
),

],
),
),
);
}
}

Flutter Widget ExpansionPanelList

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :