Skip to content

Commit 700efd6

Browse files
committed
log out
1 parent 904620f commit 700efd6

File tree

4 files changed

+69
-8
lines changed

4 files changed

+69
-8
lines changed

lib/app_theme.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ class AppTheme {
176176
return TextStyle(
177177
fontWeight: fontWeight,
178178
fontSize: fontSize,
179-
color: isDark() ? Colors.white : Colors.black.withOpacity(0.5),
179+
color: isDark()
180+
? Colors.white.withOpacity(0.5)
181+
: Colors.black.withOpacity(0.5),
180182
fontFamily: fontFamliy);
181183
}
182184

lib/mine/mine_screen.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ class _MineScreenState extends State<MineScreen> {
2424
return Stack(
2525
children: [
2626
ListView(physics: ClampingScrollPhysics(), children: [
27-
UserInfoView(),
27+
UserInfoView(
28+
callback: () {
29+
setState(() {});
30+
},
31+
),
2832
HabitsTotalView(),
2933
UserProView(),
3034
EnterView(),
@@ -33,11 +37,12 @@ class _MineScreenState extends State<MineScreen> {
3337
)
3438
]),
3539
GestureDetector(
36-
onTap: () {
37-
Navigator.of(context)
40+
onTap: () async {
41+
await Navigator.of(context)
3842
.push(CupertinoPageRoute(builder: (context) {
3943
return SettingsScreen();
4044
}));
45+
setState(() {});
4146
},
4247
child: Container(
4348
alignment: Alignment.centerRight,

lib/mine/mine_screen_views.dart

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ import 'package:timefly/app_theme.dart';
66
import 'package:timefly/blocs/habit/habit_bloc.dart';
77
import 'package:timefly/blocs/habit/habit_state.dart';
88
import 'package:timefly/login/login_page.dart';
9+
import 'package:timefly/mine/settings_screen.dart';
910
import 'package:timefly/models/habit.dart';
11+
import 'package:timefly/models/user.dart';
1012

1113
class UserInfoView extends StatelessWidget {
14+
final VoidCallback callback;
15+
16+
const UserInfoView({Key key, this.callback}) : super(key: key);
17+
1218
@override
1319
Widget build(BuildContext context) {
20+
User user = SessionUtils.sharedInstance().currentUser;
1421
return Container(
1522
margin: EdgeInsets.only(
1623
left: 16, top: MediaQuery.of(context).padding.top + 16),
@@ -29,10 +36,28 @@ class UserInfoView extends StatelessWidget {
2936
SizedBox(
3037
width: 16,
3138
),
32-
Text(
33-
'亚索',
34-
style: AppTheme.appTheme
35-
.headline1(fontWeight: FontWeight.bold, fontSize: 22),
39+
GestureDetector(
40+
onTap: () async {
41+
if (user == null) {
42+
await Navigator.of(context)
43+
.push(CupertinoPageRoute(builder: (context) {
44+
return LoginPage();
45+
}));
46+
return;
47+
}
48+
if (user.username == null || user.username.isEmpty) {
49+
await Navigator.of(context)
50+
.push(CupertinoPageRoute(builder: (context) {
51+
return SettingsScreen();
52+
}));
53+
callback();
54+
}
55+
},
56+
child: Text(
57+
'${(user == null || user.username == null || user.username.isEmpty) ? '编辑名字' : user.username}',
58+
style: AppTheme.appTheme
59+
.headline1(fontWeight: FontWeight.bold, fontSize: 22),
60+
),
3661
)
3762
],
3863
),

lib/mine/settings_screen.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:timefly/blocs/theme/theme_bloc.dart';
88
import 'package:timefly/blocs/theme/theme_event.dart';
99
import 'package:timefly/blocs/theme/theme_state.dart';
1010
import 'package:timefly/models/user.dart';
11+
import 'package:timefly/utils/flash_helper.dart';
1112
import 'package:timefly/utils/system_util.dart';
1213
import 'package:timefly/widget/custom_edit_field.dart';
1314

@@ -70,6 +71,30 @@ class _SettingsScreenState extends State<SettingsScreen> {
7071
shared.setString(COLOR_MODE, colorMode.toString());
7172
},
7273
),
74+
GestureDetector(
75+
onTap: () {
76+
SessionUtils.sharedInstance().logout();
77+
Navigator.of(context).pop();
78+
},
79+
child: Container(
80+
alignment: Alignment.center,
81+
margin: EdgeInsets.only(
82+
left: 32, right: 32, top: 48, bottom: 32),
83+
height: 55,
84+
width: 220,
85+
decoration: BoxDecoration(
86+
boxShadow: AppTheme.appTheme.coloredBoxShadow(),
87+
gradient: AppTheme.appTheme.containerGradient(),
88+
borderRadius: BorderRadius.all(Radius.circular(35))),
89+
child: Text(
90+
'退出',
91+
style: AppTheme.appTheme.headline1(
92+
textColor: Colors.white,
93+
fontSize: 18,
94+
fontWeight: FontWeight.w600),
95+
),
96+
),
97+
),
7398
SizedBox(
7499
height: 100,
75100
)
@@ -165,6 +190,10 @@ class _ChangeUserInfoViewState extends State<ChangeUserInfoView> {
165190
},
166191
onCompleted: () async {
167192
FocusScope.of(context).requestFocus(FocusNode());
193+
if (userName.isEmpty) {
194+
FlashHelper.toast(context, '请输入名字');
195+
return;
196+
}
168197
User user = SessionUtils.sharedInstance().currentUser;
169198
BmobUser bmobUser = BmobUser();
170199
bmobUser.objectId = user.id;

0 commit comments

Comments
 (0)