Skip to content

Commit 5f828fb

Browse files
author
yangshangzhi
committed
优化结构
1 parent d8ca335 commit 5f828fb

File tree

24 files changed

+116
-91
lines changed

24 files changed

+116
-91
lines changed

lib/components/baseComp.dart

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
import 'package:flutter/material.dart';
2-
import 'package:efox_flutter/store/STORE.dart';
2+
import 'package:efox_flutter/store/store.dart' show STORE;
3+
import 'header.dart' as Header;
34

45
class Index extends StatelessWidget {
56
final dynamic child;
67
final String title;
78

8-
Index({Key key, this.title, this.child}):super(key: key);
9+
Index({Key key, this.title, this.child}) : super(key: key);
910

1011
@override
11-
Widget build (BuildContext context ) {
12-
return STORE.connect(
13-
builder: (context, child, model) {
14-
return Scaffold(
15-
appBar: AppBar(
16-
title: Text(this.title),
17-
),
18-
body: ListView(
19-
children: [
20-
this.child(context, child, model)
21-
],
22-
),
23-
);
24-
}
25-
);
12+
Widget build(BuildContext context) {
13+
return STORE.connect(builder: (context, child, model) {
14+
return Scaffold(
15+
appBar: AppBar(
16+
title: Header.Index(this.title),
17+
),
18+
body: ListView(
19+
children: [this.child(context, child, model)],
20+
),
21+
);
22+
});
2623
}
2724
}
2825

lib/components/exampleComp.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:efox_flutter/store/models/main_state_model.dart' show MainStateModel;
3-
import 'package:efox_flutter/store/STORE.dart' show STORE;
3+
import 'package:efox_flutter/store/store.dart' show STORE;
44

55
class Index extends StatelessWidget {
66
final Widget child;

lib/components/header.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import 'package:flutter/material.dart';
2+
3+
class Index extends StatelessWidget {
4+
final String text;
5+
Index(this.text);
6+
@override
7+
Widget build(BuildContext context) {
8+
return Text(
9+
this.text,
10+
style: TextStyle(
11+
// fontStyle: FontStyle.normal,
12+
),
13+
);
14+
}
15+
}

lib/components/webviewComp.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'header.dart' as Header;
23
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
34

45
class Index extends StatelessWidget {
@@ -12,12 +13,13 @@ class Index extends StatelessWidget {
1213
print('url ${url}');
1314
});
1415
}
16+
1517
@override
1618
Widget build(BuildContext context) {
1719
return WebviewScaffold(
1820
url: this.url,
1921
appBar: new AppBar(
20-
title: new Text("Webview"),
22+
title: Header.Index(this.title),
2123
),
2224
withZoom: true,
2325
withLocalStorage: true,

lib/components/widgetComp.dart

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
2-
import 'package:efox_flutter/store/STORE.dart' show STORE;
2+
import 'package:efox_flutter/store/store.dart' show STORE;
3+
import 'header.dart' as Header;
34
import 'package:efox_flutter/components/markdownComp.dart' as MarkDownComp;
45
import 'package:efox_flutter/lang/app_translations.dart' show AppTranslations;
56
import 'package:efox_flutter/components/baseComp.dart' as BaseComp;
@@ -13,10 +14,10 @@ class Index extends StatefulWidget {
1314
final String originCodeUrl;
1415
final String codeUrl;
1516
final String mdUrl;
16-
final String name;
17+
final String title;
1718
Index({
1819
Key key,
19-
this.name,
20+
this.title,
2021
this.demoChild,
2122
this.originCodeUrl,
2223
this.codeUrl,
@@ -25,7 +26,7 @@ class Index extends StatefulWidget {
2526

2627
@override
2728
State<StatefulWidget> createState() => IndexState(
28-
name: name,
29+
title: title,
2930
demoChild: demoChild,
3031
originCodeUrl: originCodeUrl,
3132
codeUrl: codeUrl,
@@ -40,13 +41,13 @@ class IndexState extends State<Index> {
4041
final String originCodeUrl;
4142
final String codeUrl;
4243
final String mdUrl;
43-
final String name;
44+
final String title;
4445
bool loading = true;
4546
dynamic model;
4647

4748
IndexState({
4849
Key key,
49-
this.name,
50+
this.title,
5051
this.modelChild,
5152
this.mdList,
5253
this.demoChild,
@@ -63,15 +64,17 @@ class IndexState extends State<Index> {
6364

6465
void init() async {
6566
this._bodyList.length = 0;
66-
this._bodyList.add(await MarkDownComp.Index(await this.getMdFile(this.mdUrl)));
67+
this
68+
._bodyList
69+
.add(await MarkDownComp.Index(await this.getMdFile(this.mdUrl)));
6770

6871
// 增加
6972
if (this.demoChild != null) {
7073
this.demoChild.forEach((Widget item) {
7174
this._bodyList.add(ExampleComp.Index(child: item));
7275
});
7376
}
74-
77+
7578
setState(() {
7679
this.loading = false;
7780
});
@@ -83,7 +86,7 @@ class IndexState extends State<Index> {
8386
this.model = model;
8487
return Scaffold(
8588
appBar: AppBar(
86-
title: Text(this.name),
89+
title: Header.Index(this.title),
8790
actions: this.getActions(context, model),
8891
),
8992
body: this.loading ? this.renderLoading() : this.renderWidget(),
@@ -102,7 +105,7 @@ class IndexState extends State<Index> {
102105
Navigator.of(context).push(
103106
MaterialPageRoute(builder: (BuildContext context) {
104107
return BaseComp.Index(
105-
title: this.name,
108+
title: this.title,
106109
child: (context, child, model) {
107110
return MarkDownComp.Index(mdStr);
108111
},
@@ -163,7 +166,9 @@ class IndexState extends State<Index> {
163166
child: Row(children: [
164167
Icon(
165168
Icons.home,
169+
color: Color(model.theme.blackColor),
166170
),
171+
Text(" "),
167172
Text('官网'),
168173
]),
169174
value: 0,
@@ -172,7 +177,9 @@ class IndexState extends State<Index> {
172177
child: Row(children: [
173178
Icon(
174179
Icons.all_inclusive,
180+
color: Color(model.theme.blackColor),
175181
),
182+
Text(" "),
176183
Text("Markdown"),
177184
]),
178185
value: 1,
@@ -181,8 +188,10 @@ class IndexState extends State<Index> {
181188
child: Row(children: [
182189
Icon(
183190
Icons.code,
191+
color: Color(model.theme.blackColor),
184192
),
185-
Text(this.name),
193+
Text(" "),
194+
Text(this.title),
186195
]),
187196
value: 2,
188197
),
@@ -217,15 +226,16 @@ class IndexState extends State<Index> {
217226
mainAxisSize: MainAxisSize.min,
218227
children: <Widget>[
219228
CircularProgressIndicator(
220-
backgroundColor: Color(this.model.theme.secondColor),
229+
// backgroundColor: Color(this.model.theme.mainColor),
230+
strokeWidth: 4,
221231
),
222232
Container(
223233
padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 0),
224234
child: Text(
225235
AppTranslations.of(context).t('loading'),
226236
style: TextStyle(
227237
color: Color(this.model.theme.secondColor),
228-
fontSize: 16.0),
238+
fontSize: 20.0),
229239
),
230240
)
231241
],

lib/main.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class MainAppState extends State<MainApp> {
5757
],
5858
title: 'Flutter Demo',
5959
theme: ThemeData(
60-
// primarySwatch: Colors.blue,
6160
textTheme: TextTheme(
6261
body1: TextStyle(
6362
// color: Colors.black,
@@ -67,16 +66,16 @@ class MainAppState extends State<MainApp> {
6766
platform: TargetPlatform.iOS,
6867
iconTheme: IconThemeData(
6968
size: 32,
70-
color: Colors.grey.shade900,
69+
color: Color(model.theme.thirdColor),
7170
opacity: 0.85,
7271
),
72+
// primaryIconTheme 导航栏按钮颜色
7373
primaryIconTheme: IconThemeData(
74-
color: Colors.black,
74+
color: Color(model.theme.secondColor),
7575
),
76-
accentColor: Colors.grey,
77-
accentColorBrightness: Brightness.light,
78-
primaryColor: Colors.redAccent, // appbar背景
79-
scaffoldBackgroundColor: Colors.grey.shade50, // 整体的scaffold背景颜色
76+
accentColor: Colors.grey, // 选中颜色
77+
primaryColor: Color(model.theme.mainColor), // appbar背景
78+
scaffoldBackgroundColor: Color(model.theme.thirdColor), // 整体的scaffold背景颜色
8079
),
8180
onGenerateRoute: FluroRouter.router.generator,
8281
),

lib/page/component/index.dart

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class Index extends StatefulWidget {
1414
class _IndexState extends State<Index> {
1515
final MainStateModel model;
1616
List mapList = [];
17+
int index;
1718
_IndexState({Key key, this.model});
19+
1820
@override
1921
initState() {
2022
super.initState();
@@ -41,7 +43,7 @@ class _IndexState extends State<Index> {
4143
fontFamily: 'MaterialIcons',
4244
matchTextDirection: true,
4345
),
44-
color: Color(model.theme.mainColor),
46+
// color: Color(model.theme.mainColor),
4547
),
4648
backgroundColor: Colors.white,
4749
children: [
@@ -56,9 +58,10 @@ class _IndexState extends State<Index> {
5658
return Container(
5759
decoration: BoxDecoration(
5860
border: Border(
59-
bottom: BorderSide(
60-
width: .1,
61-
)),
61+
bottom: BorderSide(
62+
width: .1,
63+
),
64+
),
6265
),
6366
child: Column(
6467
mainAxisAlignment: MainAxisAlignment.center,
@@ -71,16 +74,17 @@ class _IndexState extends State<Index> {
7174
fontFamily: 'MaterialIcons',
7275
matchTextDirection: true,
7376
),
77+
color: Color(model.theme.mainColor),
7478
),
7579
onPressed: () {
7680
FluroRouter.router.navigateTo(
7781
context,
78-
nameSpaces + _tmpWidgetList[index].name,
82+
nameSpaces + _tmpWidgetList[index].title,
7983
);
8084
},
8185
),
8286
Text(
83-
_tmpWidgetList[index].name,
87+
_tmpWidgetList[index].title,
8488
),
8589
],
8690
),
@@ -89,7 +93,6 @@ class _IndexState extends State<Index> {
8993
),
9094
),
9195
],
92-
initiallyExpanded: false,
9396
);
9497
}
9598

@@ -98,11 +101,9 @@ class _IndexState extends State<Index> {
98101
physics: BouncingScrollPhysics(),
99102
padding: EdgeInsets.all(10),
100103
child: Column(
101-
children: mapList.map(
102-
(widgetsItem) {
103-
return renderExpanel(model, widgetsItem);
104-
},
105-
).toList(),
104+
children: List.generate(mapList.length, (_index) {
105+
return renderExpanel(model, mapList[_index]);
106+
}),
106107
),
107108
);
108109
}

lib/page/home.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import 'package:flutter/material.dart';
22
import 'package:efox_flutter/lang/application.dart';
33
import 'package:efox_flutter/lang/app_translations.dart';
44
//
5-
import 'package:efox_flutter/store/STORE.dart';
5+
import 'package:efox_flutter/store/store.dart' show STORE, MainStateModel;
66

7+
import 'package:efox_flutter/components/header.dart' as Header;
78
import 'component/index.dart' as TabIndex;
89
import 'mine/index.dart' as MyIndex;
910

@@ -24,7 +25,7 @@ class _IndexState extends State<Index> with SingleTickerProviderStateMixin {
2425
border: Border(
2526
top: BorderSide(
2627
width: .1,
27-
color: Color(model.theme.mainColor),
28+
color: Color(model.theme.greyColor),
2829
),
2930
),
3031
),
@@ -38,7 +39,7 @@ class _IndexState extends State<Index> with SingleTickerProviderStateMixin {
3839
),
3940
),
4041
labelColor: Color(model.theme.mainColor),
41-
unselectedLabelColor: Color(model.theme.thirdColor),
42+
unselectedLabelColor: Color(model.theme.greyColor),
4243
indicatorSize: TabBarIndicatorSize.tab,
4344
indicatorColor: Color(model.theme.secondColor),
4445
labelStyle: TextStyle(
@@ -110,7 +111,7 @@ class _IndexState extends State<Index> with SingleTickerProviderStateMixin {
110111
length: 2,
111112
child: Scaffold(
112113
appBar: AppBar(
113-
title: Text(lang.t('title')),
114+
title: Header.Index(lang.t('title')),
114115
actions: appBarActions(model),
115116
),
116117
bottomNavigationBar: menu(model),

lib/router/index.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class FluroRouter {
2626
print('widgetsItem $widgetsItem');
2727
widgetsItem.widgetList.forEach((itemInfo) {
2828
router.define(
29-
widgetsItem.nameSpaces + itemInfo.name,
29+
widgetsItem.nameSpaces + itemInfo.title,
3030
handler: Handler(
3131
handlerFunc: (BuildContext context, Map<String, List> params) {
3232
return itemInfo.widget;

lib/store/STORE.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import './models/main_state_model.dart';
33
export './models/main_state_model.dart';
44

55
/**
6-
* import 'package:efox_flutter/store/STORE.dart' as Store;
6+
* import 'package:efox_flutter/store/store.dart' as Store;
77
* Store.model.config.state.isPro
88
*/
99
class STORE {

0 commit comments

Comments
 (0)