Skip to content

Commit ec7a819

Browse files
committed
feat:优化首页功能
1 parent f267807 commit ec7a819

File tree

2 files changed

+76
-83
lines changed

2 files changed

+76
-83
lines changed

lib/page/component/index.dart

Lines changed: 75 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -12,112 +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;
1919

2020
_IndexState({Key key, this.model});
2121

2222
@override
2323
initState() {
2424
super.initState();
25-
this.mapList = WidgetRoot.getAllWidgets();
25+
this._mapList = WidgetRoot.getAllWidgets();
2626
}
2727

28-
/**
29-
* 渲染折叠板
30-
*/
31-
Widget renderExpanel(MainStateModel model, widgetsItem) {
28+
renderPanel(model, widgetsItem, index) {
3229
String nameSpaces = widgetsItem.nameSpaces;
3330
List _tmpWidgetList = widgetsItem.widgetList;
34-
return ExpansionTile(
35-
onExpansionChanged: (isOpen) {
36-
print(isOpen);
37-
},
38-
title: Text(
39-
widgetsItem.typeName,
40-
style: TextStyle(
41-
fontSize: 20,
42-
fontWeight: FontWeight.bold,
43-
),
44-
),
45-
leading: Icon(
46-
IconData(
47-
widgetsItem.code,
48-
fontFamily: 'MaterialIcons',
49-
matchTextDirection: true,
50-
),
51-
// color: Color(AppTheme.mainColor),
52-
),
53-
backgroundColor: Colors.grey.shade100.withOpacity(0.1),
54-
children: [
55-
Container(
56-
decoration: BoxDecoration(
57-
color: Colors.grey.shade100,
58-
borderRadius: BorderRadius.all(
59-
Radius.circular(20),
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+
),
6042
),
43+
title: Text('${widgetsItem.typeName}'),
6144
),
62-
child: GridView.count(
63-
shrinkWrap: true,
64-
physics: NeverScrollableScrollPhysics(),
65-
childAspectRatio: 1,
66-
crossAxisCount: 3,
67-
children: List.generate(
68-
_tmpWidgetList.length,
69-
(index) {
70-
return Container(
71-
decoration: BoxDecoration(
72-
border: Border(
73-
bottom: BorderSide(
74-
width: .1,
75-
),
45+
);
46+
},
47+
body: Container(
48+
decoration: BoxDecoration(
49+
color: Color(AppTheme.thirdColor),
50+
),
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,
7671
),
72+
// color: Colors.white,
73+
size: 48,
7774
),
78-
child: Column(
79-
mainAxisAlignment: MainAxisAlignment.center,
80-
children: [
81-
IconButton(
82-
iconSize: 48,
83-
icon: Icon(
84-
IconData(
85-
_tmpWidgetList[index].code ?? 59101,
86-
fontFamily: 'MaterialIcons',
87-
matchTextDirection: true,
88-
),
89-
color: Color(AppTheme.mainColor),
90-
),
91-
onPressed: () {
92-
FluroRouter.router.navigateTo(
93-
context,
94-
nameSpaces + _tmpWidgetList[index].title,
95-
);
96-
},
97-
),
98-
Text(
99-
_tmpWidgetList[index].title,
100-
overflow: TextOverflow.ellipsis,
101-
),
102-
],
103-
),
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,
10485
);
10586
},
106-
),
107-
),
87+
);
88+
}),
10889
),
109-
],
90+
),
91+
isExpanded: _isExpandedIndex == index,
11092
);
11193
}
11294

11395
Widget build(BuildContext context) {
11496
return SingleChildScrollView(
11597
physics: BouncingScrollPhysics(),
116-
padding: EdgeInsets.all(10),
117-
child: Column(
118-
children: List.generate(mapList.length, (_index) {
119-
return renderExpanel(model, mapList[_index]);
120-
}),
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+
},
121114
),
122115
);
123116
}

lib/page/home.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Index extends StatefulWidget {
1313
_IndexState createState() => new _IndexState();
1414
}
1515

16-
class _IndexState extends State<Index> with SingleTickerProviderStateMixin {
16+
class _IndexState extends State<Index> {
1717
int _currentIndex = 0;
1818
PageController _pageController;
1919

0 commit comments

Comments
 (0)