Skip to content

Commit 6f86796

Browse files
committed
feat: 增加assetbundle、优化登录
1 parent 61e2463 commit 6f86796

File tree

11 files changed

+340
-199
lines changed

11 files changed

+340
-199
lines changed
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1-
## **文档完善中**
1+
## **AssetBundle**
2+
> 抽象类,资源读取
3+
4+
#### 使用
5+
```
6+
import 'package:flutter/services.dart' show rootBundle;
7+
8+
getText() async {
9+
String text = await rootBundle.loadString('locale/zh.json');
10+
print('text $text');
11+
}
12+
13+
```

lib/controller/index.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'package:efox_flutter/utils/appVersion.dart' show AppVersion;
66
void initState() {
77
// 获取版本号
88
Store.valueNotCtx<ConfigModel>().$getAppVersion();
9-
// Store.valueNotCtx<UserModel>().$getUserInfo();
109
// 登录
1110
Store.valueNotCtx<UserModel>().$getLocalUserInfo();
1211
Future.delayed(Duration(seconds: 3), () {

lib/http/index.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Dio getDio({options, loading}) {
4444
print('=========【请求成功】Start============');
4545
print("请求地址 ${response.request.uri}");
4646
print("请求头 ${response.statusCode}");
47-
print("请求参数 ${response.data}");
47+
print("返回值 ${response.data}");
4848
print('=========【请求成功】End============');
4949
await AppLoading.afterResponse(response.request.uri, loading);
5050
return response;

lib/main.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import 'package:efox_flutter/store/index.dart'
88
import 'package:efox_flutter/router/index.dart' show FluroRouter; //路由
99
import 'package:efox_flutter/config/theme.dart' show AppTheme; //主题
1010
import 'package:efox_flutter/utils/analytics.dart' as Analytics; //统计
11-
11+
// import './mock/index.dart' as TestCase;
1212
class MainApp extends StatefulWidget {
1313
MainApp() {
1414
FluroRouter.initRouter();
15+
// TestCase.runTestCase();
1516
}
1617

1718
@override

lib/mock/index.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import 'login.dart' as LoginTest;
2+
3+
runTestCase () async {
4+
await LoginTest.testLogin();
5+
}

lib/mock/login.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'package:efox_flutter/store/objects/user_info.dart' show UserInfo;
2+
const user = {
3+
"id": 123,
4+
"plan": {
5+
'name': '123'
6+
}
7+
};
8+
9+
testLogin () {
10+
UserInfo _user = UserInfo.fromJson(user);
11+
print('_user $_user');
12+
print('_user ${_user.plan.name}');
13+
}

lib/page/app_login/index.dart

Lines changed: 172 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'dart:math' as math;
23
import 'package:efox_flutter/lang/index.dart' show AppLocalizations;
34
import 'package:efox_flutter/store/index.dart' show Store, UserModel;
45

@@ -14,116 +15,190 @@ class _IndexState extends State<Index> {
1415
TextEditingController pwdCtl = TextEditingController(text: '');
1516

1617
GlobalKey _formKey = GlobalKey<FormState>();
18+
OverlayState _overlayState;
19+
OverlayEntry _overlayEntry;
20+
21+
/**
22+
* 弹窗内容
23+
*/
24+
renderOverlay(String text) {
25+
_overlayEntry?.remove();
26+
_overlayState = Overlay.of(context);
27+
_overlayEntry = OverlayEntry(builder: (context) {
28+
return Center(child: Text(text));
29+
});
30+
_overlayState.insert(_overlayEntry);
31+
}
32+
33+
/**
34+
* 顶部图标
35+
*/
36+
renderGithubImage() {
37+
return Row(
38+
mainAxisAlignment: MainAxisAlignment.center,
39+
children: <Widget>[
40+
Image.asset(
41+
'assets/imgs/github_2.png',
42+
width: 50,
43+
height: 50,
44+
),
45+
SizedBox(
46+
width: 10,
47+
),
48+
Transform.rotate(
49+
child: Icon(
50+
Icons.import_export,
51+
color: Colors.black,
52+
),
53+
angle: math.pi / 2,
54+
),
55+
SizedBox(
56+
width: 10,
57+
),
58+
Image.asset(
59+
'assets/imgs/github_1.png',
60+
width: 50,
61+
height: 50,
62+
),
63+
],
64+
);
65+
}
66+
1767
@override
1868
Widget build(BuildContext ctx) {
19-
return Scaffold(
20-
appBar: AppBar(
21-
centerTitle: true,
22-
title: Text(
23-
AppLocalizations.$t('common.login'),
24-
textAlign: TextAlign.center,
69+
return WillPopScope(
70+
child: Scaffold(
71+
appBar: AppBar(
72+
centerTitle: true,
73+
title: Text(
74+
AppLocalizations.$t('common.login'),
75+
textAlign: TextAlign.center,
76+
),
77+
automaticallyImplyLeading: false,
2578
),
26-
automaticallyImplyLeading: false,
27-
),
28-
body: Builder(builder: (BuildContext context) {
29-
// Store.setWidgetCtx(context);
30-
return SingleChildScrollView(
31-
child: Padding(
32-
padding: EdgeInsets.symmetric(vertical: 50, horizontal: 24),
33-
child: Form(
34-
key: _formKey,
35-
autovalidate: true,
36-
child: Column(
37-
children: <Widget>[
38-
TextFormField(
39-
controller: nameCtl,
40-
autofocus: true,
41-
decoration: InputDecoration(
42-
labelText: AppLocalizations.$t('login.account'),
43-
hintText: AppLocalizations.$t('login.account_tips'),
44-
icon: Icon(Icons.person),
79+
body: Builder(builder: (BuildContext context) {
80+
return SingleChildScrollView(
81+
child: Padding(
82+
padding: EdgeInsets.symmetric(vertical: 50, horizontal: 24),
83+
child: Form(
84+
key: _formKey,
85+
autovalidate: true,
86+
child: Column(
87+
children: <Widget>[
88+
renderGithubImage(),
89+
TextFormField(
90+
controller: nameCtl,
91+
autofocus: true,
92+
decoration: InputDecoration(
93+
labelText: AppLocalizations.$t('login.account'),
94+
hintText: AppLocalizations.$t('login.account_tips'),
95+
icon: Icon(Icons.person),
96+
),
97+
validator: (v) {
98+
return v.trim().length > 0
99+
? null
100+
: AppLocalizations.$t('login.account_error_tips');
101+
},
102+
),
103+
TextFormField(
104+
controller: pwdCtl,
105+
decoration: InputDecoration(
106+
labelText: AppLocalizations.$t('login.password'),
107+
hintText: AppLocalizations.$t('login.password_tips'),
108+
icon: Icon(Icons.lock),
109+
),
110+
obscureText: true,
111+
validator: (v) {
112+
return v.trim().length > 0
113+
? null
114+
: AppLocalizations.$t('login.password_error_tips');
115+
},
116+
),
117+
Padding(
118+
padding: EdgeInsets.only(top: 50),
119+
child: Row(
120+
children: <Widget>[
121+
Expanded(
122+
child: RaisedButton(
123+
padding: EdgeInsets.all(15),
124+
color: Theme.of(context).primaryColor,
125+
textColor: Theme.of(context)
126+
.primaryTextTheme
127+
.title
128+
.color,
129+
child: Text(
130+
AppLocalizations.$t('common.login'),
131+
),
132+
onPressed: () async {
133+
if ((_formKey.currentState as FormState)
134+
.validate()) {
135+
await Store.value<UserModel>(context)
136+
.$loginController(context, {
137+
'name': nameCtl.text,
138+
'pwd': pwdCtl.text
139+
});
140+
}
141+
},
142+
),
143+
)
144+
],
145+
),
45146
),
46-
validator: (v) {
47-
return v.trim().length > 0 ? null : AppLocalizations.$t('login.account_error_tips');
48-
},
49-
),
50-
TextFormField(
51-
controller: pwdCtl,
52-
decoration: InputDecoration(
53-
labelText: AppLocalizations.$t('login.password'),
54-
hintText: AppLocalizations.$t('login.password_tips'),
55-
icon: Icon(Icons.lock),
147+
SizedBox(
148+
height: 10,
56149
),
57-
obscureText: true,
58-
validator: (v) {
59-
return v.trim().length > 0 ? null : AppLocalizations.$t('login.password_error_tips');
60-
},
61-
),
62-
Padding(
63-
padding: EdgeInsets.only(top: 50),
64-
child: Row(
150+
Row(
151+
mainAxisAlignment: MainAxisAlignment.center,
65152
children: <Widget>[
66-
Expanded(
67-
child: RaisedButton(
68-
padding: EdgeInsets.all(15),
69-
color: Theme.of(context).primaryColor,
70-
textColor:
71-
Theme.of(context).primaryTextTheme.title.color,
72-
child: Text(
73-
AppLocalizations.$t('common.login'),
153+
GestureDetector(
154+
child: Text(
155+
'Github账户登录说明',
156+
style: TextStyle(
157+
decoration: TextDecoration.underline,
158+
textBaseline: TextBaseline.ideographic,
159+
decorationColor: Color(0xff000000),
74160
),
75-
onPressed: () async {
76-
if ((_formKey.currentState as FormState)
77-
.validate()) {
78-
Store.value<UserModel>(context)
79-
.$loginController(context, {
80-
'name': nameCtl.text,
81-
'pwd': pwdCtl.text
82-
});
83-
}
84-
},
85-
),
86-
)
87-
],
88-
),
89-
),
90-
SizedBox(
91-
height: 10,
92-
),
93-
Row(
94-
mainAxisAlignment: MainAxisAlignment.center,
95-
children: <Widget>[
96-
GestureDetector(
97-
child: Text(
98-
'Github账户登录说明',
99-
style: TextStyle(
100-
decoration: TextDecoration.underline,
101-
textBaseline: TextBaseline.ideographic,
102-
decorationColor: Color(0xff000000),
103161
),
162+
onTap: () {
163+
renderOverlay(" Text 1");
164+
},
104165
),
105-
),
106-
SizedBox(
107-
width: 10,
108-
),
109-
GestureDetector(
110-
child: Text(
111-
'软件许可及服务协议',
112-
style: TextStyle(
113-
decoration: TextDecoration.underline,
114-
textBaseline: TextBaseline.ideographic,
115-
decorationColor: const Color(0xff000000),
166+
SizedBox(
167+
width: 10,
168+
),
169+
GestureDetector(
170+
child: Text(
171+
'软件许可及服务协议',
172+
style: TextStyle(
173+
decoration: TextDecoration.underline,
174+
textBaseline: TextBaseline.ideographic,
175+
decorationColor: const Color(0xff000000),
176+
),
116177
),
178+
onTap: () {
179+
renderOverlay(" Text 2");
180+
},
117181
),
118-
),
119-
],
120-
)
121-
],
182+
],
183+
)
184+
],
185+
),
122186
),
123187
),
124-
),
125-
);
126-
}),
188+
);
189+
}),
190+
),
191+
onWillPop: () {
192+
beforeDispose();
193+
},
127194
);
128195
}
196+
beforeDispose() {
197+
if (_overlayEntry != null) {
198+
_overlayEntry.remove();
199+
_overlayEntry = null;
200+
} else {
201+
Navigator.of(context).pop();
202+
}
203+
}
129204
}

lib/page/home.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class _IndexState extends State<Index> {
5656
onTap: () {
5757
Store.value<UserModel>(context).$clearUserInfo();
5858
},
59-
)
59+
),
6060
];
6161
}
6262
return [
@@ -113,7 +113,7 @@ class _IndexState extends State<Index> {
113113
),
114114
Expanded(
115115
child: ListView(
116-
children: renderTiles(model.user.node_id),
116+
children: renderTiles(model.user.id),
117117
),
118118
),
119119
],

0 commit comments

Comments
 (0)