Skip to content

Commit 5bb7581

Browse files
committed
refactor:优化首页功能
1 parent 9ead94b commit 5bb7581

File tree

4 files changed

+215
-16
lines changed

4 files changed

+215
-16
lines changed

lib/config/theme.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ class AppTheme {
66
static int thirdColor = 0xFFFAFAFA;
77
static int greyColor = 0x8A000000;
88
static int blackColor = 0xFF000000;
9+
static int lineColor = 0xFFEEEEEE;
910
static ThemeData themData = ThemeData(
1011
textTheme: TextTheme(
1112
body1: TextStyle(
1213
// color: Colors.black,
1314
// fontWeight: FontWeight.bold,
1415
),
1516
),
16-
platform: TargetPlatform.iOS,
17+
//platform: TargetPlatform.iOS,
1718
iconTheme: IconThemeData(
1819
size: 32,
1920
color: Color(thirdColor),
@@ -25,6 +26,6 @@ class AppTheme {
2526
),
2627
accentColor: Colors.grey, // 选中颜色
2728
primaryColor: Color(mainColor), // appbar背景
28-
scaffoldBackgroundColor: Color(thirdColor), // 整体的scaffold背景颜色
29+
scaffoldBackgroundColor: Color(secondColor), // 整体的scaffold背景颜色
2930
);
3031
}

lib/page/component/tabs.dart

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:efox_flutter/store/models/main_state_model.dart'
3+
show MainStateModel;
4+
import 'package:efox_flutter/config/theme.dart' show AppTheme;
5+
import 'package:efox_flutter/widget/index.dart' as WidgetRoot;
6+
import 'package:efox_flutter/router/index.dart' show FluroRouter;
7+
import 'package:efox_flutter/lang/index.dart' show AppLocalizations;
8+
import 'package:efox_flutter/components/headerComp.dart' as Header;
9+
10+
class Index extends StatefulWidget {
11+
final MainStateModel model;
12+
Index({Key key, this.model}) : super(key: key);
13+
@override
14+
_IndexState createState() => new _IndexState();
15+
}
16+
17+
class _IndexState extends State<Index>
18+
with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
19+
List _mapList = WidgetRoot.getAllWidgets();
20+
int _currentIndex = -1;
21+
TabController _tabController;
22+
23+
@override
24+
bool get wantKeepAlive => true;
25+
26+
@override
27+
initState() {
28+
super.initState();
29+
_tabController = new TabController(vsync: this, length: _mapList.length);
30+
_tabController.addListener(() {
31+
if (_currentIndex != _tabController.index) {
32+
_currentIndex = _tabController.index;
33+
}
34+
});
35+
}
36+
37+
@override
38+
void dispose() {
39+
_tabController.dispose();
40+
super.dispose();
41+
}
42+
43+
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
44+
45+
Widget build(BuildContext context) {
46+
return Scaffold(
47+
key: _scaffoldKey,
48+
/* appBar: AppBar(
49+
title: Header.Index(
50+
AppLocalizations.$t('nav_title_0'),
51+
),
52+
actions: appBarActions(),
53+
), */
54+
appBar: PreferredSize(
55+
preferredSize: Size.fromHeight(kToolbarHeight),
56+
child: Container(
57+
color: Color(AppTheme.mainColor),
58+
child: SafeArea(
59+
child: this._TabBar(),
60+
),
61+
),
62+
),
63+
body: Column(
64+
children: <Widget>[
65+
//this._TabBar(),
66+
this._TabView()
67+
],
68+
));
69+
}
70+
71+
Widget _TabBar() {
72+
return TabBar(
73+
controller: _tabController,
74+
isScrollable: true,
75+
tabs: _mapList.map((v) {
76+
return new Tab(
77+
text: v.typeName,
78+
/* icon: Icon(
79+
IconData(
80+
v.code,
81+
fontFamily: 'MaterialIcons',
82+
matchTextDirection: true,
83+
),
84+
), */
85+
);
86+
}).toList());
87+
}
88+
89+
Widget _TabView() {
90+
return Expanded(
91+
child: new TabBarView(
92+
controller: _tabController,
93+
children: List.generate(_mapList.length, (index) {
94+
return this.Grids(_mapList[index], index);
95+
})),
96+
);
97+
}
98+
99+
Widget Grids(widgetsItem, index) {
100+
String nameSpaces = widgetsItem.nameSpaces;
101+
List _tmpWidgetList = widgetsItem.widgetList;
102+
103+
return Container(
104+
child: GridView.count(
105+
childAspectRatio: 1.3,
106+
padding: EdgeInsets.fromLTRB(4, 0, 4, 0),
107+
shrinkWrap: true,
108+
physics: ScrollPhysics(),
109+
crossAxisCount: 3,
110+
children: List.generate(
111+
_tmpWidgetList.length,
112+
(index) {
113+
return Container(
114+
decoration: BoxDecoration(
115+
border:
116+
Border.all(color: Color(AppTheme.lineColor), width: 0.5)),
117+
child: FlatButton(
118+
color: Color(AppTheme.secondColor),
119+
splashColor: Color(AppTheme.mainColor),
120+
child: Column(
121+
crossAxisAlignment: CrossAxisAlignment.center,
122+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
123+
children: [
124+
Icon(
125+
IconData(
126+
_tmpWidgetList[index].code,
127+
fontFamily: 'MaterialIcons',
128+
matchTextDirection: true,
129+
),
130+
color: Color(AppTheme.mainColor),
131+
size: 32,
132+
),
133+
Text(
134+
'${_tmpWidgetList[index].title}',
135+
//overflow: TextOverflow.ellipsis,
136+
style:
137+
TextStyle(fontSize: 14, fontWeight: FontWeight.w300),
138+
)
139+
],
140+
),
141+
onPressed: () {
142+
FluroRouter.router.navigateTo(
143+
context,
144+
nameSpaces + _tmpWidgetList[index].title,
145+
);
146+
},
147+
),
148+
);
149+
},
150+
),
151+
),
152+
);
153+
}
154+
155+
List<Widget> appBarActions() {
156+
return [
157+
PopupMenuButton(
158+
icon: Icon(
159+
Icons.more_vert,
160+
),
161+
onSelected: (local) {
162+
AppLocalizations.changeLanguage(Locale(local));
163+
print('local=$local');
164+
},
165+
itemBuilder: (context) => [
166+
PopupMenuItem(
167+
child: Row(
168+
children: <Widget>[
169+
Text('中文'),
170+
],
171+
),
172+
value: 'zh',
173+
),
174+
PopupMenuItem(
175+
child: Row(
176+
children: <Widget>[
177+
Text('english'),
178+
],
179+
),
180+
value: 'en',
181+
),
182+
],
183+
),
184+
];
185+
}
186+
}

lib/page/home.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import 'package:efox_flutter/lang/index.dart' show AppLocalizations;
33
import 'package:efox_flutter/store/index.dart' show Store;
44
import 'package:efox_flutter/controller/index.dart' as Controller;
55

6-
import 'component/index.dart' as TabIndex;
6+
//import 'component/index.dart' as TabIndex;
7+
import 'component/tabs.dart' as TabIndex;
78
import 'mine/index.dart' as MyIndex;
89

910
class Index extends StatefulWidget {
@@ -35,7 +36,8 @@ class _IndexState extends State<Index> {
3536
title: Text(AppLocalizations.$t('title_component')),
3637
icon: Icon(Icons.dashboard)),
3738
BottomNavigationBarItem(
38-
title: Text(AppLocalizations.$t('title_my')), icon: Icon(Icons.person_outline)),
39+
title: Text(AppLocalizations.$t('title_my')),
40+
icon: Icon(Icons.person_outline)),
3941
],
4042
type: BottomNavigationBarType.fixed,
4143
currentIndex: _currentIndex,

lib/page/mine/index.dart

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:efox_flutter/lang/index.dart' show AppLocalizations;
33
import 'package:efox_flutter/router/index.dart' show FluroRouter;
4+
import 'package:efox_flutter/config/theme.dart' show AppTheme;
45

56
class _IndexState extends State<Index> {
67
@override
@@ -16,7 +17,9 @@ class _IndexState extends State<Index> {
1617
'index': 0
1718
},
1819
{
19-
'name': widget.model.config.state.isPro ? AppLocalizations.$t('mine.loadLocal') : AppLocalizations.$t('mine.loadNetwork'),
20+
'name': widget.model.config.state.isPro
21+
? AppLocalizations.$t('mine.loadLocal')
22+
: AppLocalizations.$t('mine.loadNetwork'),
2023
'icon': 57539, // import_export
2124
'index': 2,
2225
},
@@ -86,18 +89,25 @@ class _IndexState extends State<Index> {
8689
(context, index) {
8790
dynamic item = list[index];
8891
if (item['show'] ?? true) {
89-
return ListTile(
90-
onTap: () {
91-
this.actionsEvent(item['index']);
92-
},
93-
leading: Icon(
94-
IconData(
95-
item['icon'],
96-
fontFamily: 'MaterialIcons',
97-
matchTextDirection: true,
92+
return Column(
93+
children: <Widget>[
94+
ListTile(
95+
onTap: () {
96+
this.actionsEvent(item['index']);
97+
},
98+
leading: Icon(
99+
IconData(
100+
item['icon'],
101+
fontFamily: 'MaterialIcons',
102+
matchTextDirection: true,
103+
),
104+
),
105+
title: Text('${item['name']}'),
98106
),
99-
),
100-
title: Text('${item['name']}'),
107+
Divider(
108+
color: Color(AppTheme.lineColor),
109+
)
110+
],
101111
);
102112
} else {
103113
return Container();

0 commit comments

Comments
 (0)