@@ -12,102 +12,105 @@ class Index extends StatefulWidget {
1212 _IndexState createState () => _IndexState (model: this .model);
1313}
1414
15- class _IndexState extends State <Index > {
15+ class _IndexState extends State <Index > {
1616 final MainStateModel model;
17- List mapList = [];
18- int index;
17+ List _mapList = [];
18+ int _isExpandedIndex = - 1 ;
19+
1920 _IndexState ({Key key, this .model});
2021
2122 @override
2223 initState () {
2324 super .initState ();
24- this .mapList = WidgetRoot .getAllWidgets ();
25+ this ._mapList = WidgetRoot .getAllWidgets ();
2526 }
2627
27- /**
28- * 渲染折叠板
29- */
30- Widget renderExpanel (MainStateModel model, widgetsItem) {
28+ renderPanel (model, widgetsItem, index) {
3129 String nameSpaces = widgetsItem.nameSpaces;
3230 List _tmpWidgetList = widgetsItem.widgetList;
33- return Container (
34- margin: EdgeInsets .only (bottom: 10 ),
35- child: ExpansionTile (
36- title: Text (
37- widgetsItem.typeName,
38- style: TextStyle (
39- fontSize: 20 ,
40- fontWeight: FontWeight .bold,
41- ),
42- ),
43- leading: Icon (
44- IconData (
45- widgetsItem.code ?? 58353 ,
46- fontFamily: 'MaterialIcons' ,
47- matchTextDirection: true ,
31+ return ExpansionPanel (
32+ headerBuilder: (context, flag) {
33+ return Container (
34+ padding: EdgeInsets .all (10 ),
35+ child: ListTile (
36+ leading: Icon (
37+ IconData (
38+ widgetsItem.code,
39+ fontFamily: 'MaterialIcons' ,
40+ matchTextDirection: true ,
41+ ),
42+ ),
43+ title: Text ('${widgetsItem .typeName }' ),
4844 ),
49- // color: Color(AppTheme.mainColor),
45+ );
46+ },
47+ body: Container (
48+ decoration: BoxDecoration (
49+ color: Color (AppTheme .thirdColor),
5050 ),
51- backgroundColor: Colors .white,
52- children: [
53- GridView .count (
54- shrinkWrap: true ,
55- physics: NeverScrollableScrollPhysics (),
56- childAspectRatio: 1 ,
57- crossAxisCount: 3 ,
58- children: List .generate (
59- _tmpWidgetList.length,
60- (index) {
61- return Container (
62- decoration: BoxDecoration (
63- border: Border (
64- bottom: BorderSide (
65- width: .1 ,
66- ),
51+ padding: EdgeInsets .all (10 ),
52+ child: GridView .count (
53+ shrinkWrap: true ,
54+ physics: ScrollPhysics (),
55+ crossAxisCount: 3 ,
56+ crossAxisSpacing: 10 ,
57+ mainAxisSpacing: 10 ,
58+ children: List .generate (_tmpWidgetList.length, (index) {
59+ return RaisedButton (
60+ color: Color (AppTheme .secondColor),
61+ splashColor: Color (AppTheme .mainColor),
62+ child: Column (
63+ crossAxisAlignment: CrossAxisAlignment .center,
64+ mainAxisAlignment: MainAxisAlignment .spaceEvenly,
65+ children: [
66+ Icon (
67+ IconData (
68+ _tmpWidgetList[index].code,
69+ fontFamily: 'MaterialIcons' ,
70+ matchTextDirection: true ,
6771 ),
72+ color: Color (AppTheme .mainColor),
73+ size: 48 ,
6874 ),
69- child: Column (
70- mainAxisAlignment: MainAxisAlignment .center,
71- children: [
72- IconButton (
73- iconSize: 48 ,
74- icon: Icon (
75- IconData (
76- _tmpWidgetList[index].code ?? 59101 ,
77- fontFamily: 'MaterialIcons' ,
78- matchTextDirection: true ,
79- ),
80- color: Color (AppTheme .mainColor),
81- ),
82- onPressed: () {
83- FluroRouter .router.navigateTo (
84- context,
85- nameSpaces + _tmpWidgetList[index].title,
86- );
87- },
88- ),
89- Text (
90- _tmpWidgetList[index].title,
91- ),
92- ],
93- ),
75+ Text (
76+ '${_tmpWidgetList [index ].title }' ,
77+ overflow: TextOverflow .ellipsis,
78+ )
79+ ],
80+ ),
81+ onPressed: () {
82+ FluroRouter .router.navigateTo (
83+ context,
84+ nameSpaces + _tmpWidgetList[index].title,
9485 );
9586 },
96- ),
97- ),
98- ] ,
87+ );
88+ } ),
89+ ) ,
9990 ),
91+ isExpanded: _isExpandedIndex == index,
10092 );
10193 }
10294
10395 Widget build (BuildContext context) {
10496 return SingleChildScrollView (
10597 physics: BouncingScrollPhysics (),
106- padding: EdgeInsets .all (10 ),
107- child: Column (
108- children: List .generate (mapList.length, (_index) {
109- return renderExpanel (model, mapList[_index]);
110- }),
98+ // padding: EdgeInsets.all(10),
99+ child: ExpansionPanelList (
100+ children: List .generate (
101+ _mapList.length,
102+ (_index) {
103+ return renderPanel (model, _mapList[_index], _index);
104+ },
105+ ),
106+ expansionCallback: (index, flag) {
107+ if (flag) {
108+ index = - 1 ;
109+ }
110+ setState (() {
111+ this ._isExpandedIndex = index;
112+ });
113+ },
111114 ),
112115 );
113116 }
0 commit comments