Skip to content

Commit 61e2463

Browse files
committed
feat:优化登录功能
1 parent 72d468e commit 61e2463

File tree

5 files changed

+78
-53
lines changed

5 files changed

+78
-53
lines changed

lib/page/app_login/index.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@ class _IndexState extends State<Index> {
3939
controller: nameCtl,
4040
autofocus: true,
4141
decoration: InputDecoration(
42-
labelText: '账户名',
43-
hintText: '请输入Github账户名',
42+
labelText: AppLocalizations.$t('login.account'),
43+
hintText: AppLocalizations.$t('login.account_tips'),
4444
icon: Icon(Icons.person),
4545
),
4646
validator: (v) {
47-
return v.trim().length > 0 ? null : '用户名不能为空';
47+
return v.trim().length > 0 ? null : AppLocalizations.$t('login.account_error_tips');
4848
},
4949
),
5050
TextFormField(
5151
controller: pwdCtl,
5252
decoration: InputDecoration(
53-
labelText: '密码',
54-
hintText: '请输入登录密码',
53+
labelText: AppLocalizations.$t('login.password'),
54+
hintText: AppLocalizations.$t('login.password_tips'),
5555
icon: Icon(Icons.lock),
5656
),
5757
obscureText: true,
5858
validator: (v) {
59-
return v.trim().length > 5 ? null : "密码不能少于6位";
59+
return v.trim().length > 0 ? null : AppLocalizations.$t('login.password_error_tips');
6060
},
6161
),
6262
Padding(

lib/page/home.dart

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,52 @@ class _IndexState extends State<Index> {
4747
);
4848
}
4949

50+
List<Widget> renderTiles(id) {
51+
if (id != null) {
52+
return [
53+
ListTile(
54+
leading: Icon(Icons.exit_to_app),
55+
title: Text(AppLocalizations.$t('common.logout')),
56+
onTap: () {
57+
Store.value<UserModel>(context).$clearUserInfo();
58+
},
59+
)
60+
];
61+
}
62+
return [
63+
ListTile(
64+
leading: Icon(Icons.account_circle),
65+
title: Text(AppLocalizations.$t('common.login')),
66+
onTap: () {
67+
Navigator.of(context).push(
68+
MaterialPageRoute(
69+
builder: (BuildContext context) {
70+
return LoginIndex.Index();
71+
},
72+
),
73+
);
74+
},
75+
)
76+
];
77+
}
78+
5079
/**
5180
* 抽屉面板
5281
*/
5382
renderDrawer() {
5483
print('renderDrawer $context');
5584
return Drawer(
56-
child: Column(
57-
crossAxisAlignment: CrossAxisAlignment.start,
58-
children: <Widget>[
59-
Container(
60-
height: 200,
61-
decoration: BoxDecoration(
62-
color: Color(AppTheme.mainColor),
63-
),
64-
child: Store.connect<UserModel>(
65-
builder: (context, child, model) {
66-
return Row(children: <Widget>[
85+
child: Store.connect<UserModel>(builder: (context, child, model) {
86+
return Column(
87+
crossAxisAlignment: CrossAxisAlignment.start,
88+
children: <Widget>[
89+
Container(
90+
height: 200,
91+
decoration: BoxDecoration(
92+
color: Color(AppTheme.mainColor),
93+
),
94+
child: Row(
95+
children: <Widget>[
6796
Padding(
6897
padding: EdgeInsets.symmetric(horizontal: 20.0),
6998
child: ClipOval(
@@ -76,40 +105,20 @@ class _IndexState extends State<Index> {
76105
),
77106
),
78107
Text(
79-
Store.value<UserModel>(context).user.name ?? 'Guest',
108+
model.user.name ?? 'Guest',
80109
style: TextStyle(fontWeight: FontWeight.bold),
81110
)
82-
]);
83-
},
111+
],
112+
),
84113
),
85-
),
86-
Expanded(
87-
child: ListView(
88-
children: <Widget>[
89-
ListTile(
90-
leading: Icon(Icons.account_circle),
91-
title: Text(AppLocalizations.$t('common.login')),
92-
onTap: () {
93-
Navigator.of(context).push(
94-
MaterialPageRoute(builder: (BuildContext context) {
95-
return LoginIndex.Index();
96-
}));
97-
},
98-
),
99-
Divider(),
100-
ListTile(
101-
leading: Icon(Icons.exit_to_app),
102-
title: Text(AppLocalizations.$t('common.logout')),
103-
onTap: () {
104-
Store.value<UserModel>(context).$clearUserInfo();
105-
// Store.value<UserModel>(context).$getUserInfo();
106-
},
107-
),
108-
],
114+
Expanded(
115+
child: ListView(
116+
children: renderTiles(model.user.node_id),
117+
),
109118
),
110-
),
111-
],
112-
),
119+
],
120+
);
121+
}),
113122
);
114123
}
115124

locale/en.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"title_component": "Components",
33
"title_my": "My",
44
"common": {
5-
"login": "登录",
6-
"logout": "退出"
5+
"login": "Sign In",
6+
"logout": "Logout"
77
},
88
"common_mine_1": {
99
"cn": "CN",
@@ -19,6 +19,14 @@
1919
"loadNetwork": "Load Network Document Resources",
2020
"loadLocal": "Load Local Document Resources"
2121
},
22+
"login": {
23+
"account": "Account",
24+
"account_tips": "Please Input Account",
25+
"account_error_tips": "Account Is Not Empty",
26+
"password": "Password",
27+
"password_tips": "Please Input Password",
28+
"password_error_tips": "Password Is Not Empty"
29+
},
2230
"loading": "Loading",
2331
"ScrollComponents": "ScrollComponents",
2432
"Common": "Common",

locale/zh.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
"loadNetwork": "网络优良,可选择加载线上文档资源",
2020
"loadLocal": "网络较差时,可选择加载本地文档资源"
2121
},
22+
"login": {
23+
"account": "账户名",
24+
"account_tips": "请输入账户名",
25+
"account_error_tips": "用户名不能为空",
26+
"password": "密码",
27+
"password_tips": "请输入登录密码",
28+
"password_error_tips": "密码不能为空"
29+
},
2230
"loading": "加载中",
2331
"ScrollComponents": "滚动",
2432
"Common": "通用",

readme/develop.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ lib
99
|--app_login
1010
```
1111

12-
*不建议以下写法 *
12+
不建议以下写法
1313
```
1414
lib
1515
|--common-component 【X】
@@ -24,7 +24,7 @@ lib
2424
|--page
2525
```
2626

27-
*不建议以下写法 *
27+
不建议以下写法
2828
```
2929
lib
3030
|--commonComponent.dart 【X】
@@ -88,7 +88,7 @@ var getName (int id) {
8888
}
8989
```
9090

91-
*不推荐如下写法 *
91+
不推荐如下写法
9292

9393
```
9494
constPI = 3.14;
@@ -102,7 +102,7 @@ class Animal {
102102
```
103103
var name;
104104
```
105-
*不建议写法 *
105+
不建议写法
106106
```
107107
var name = null;
108108
```

0 commit comments

Comments
 (0)