c9df43c8
Key
feat: 修改个人信息、接口
|
1
|
import 'package:flutter/widgets.dart';
|
c61b3c1a
Key
feat: toast_util....
|
2
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
c9df43c8
Key
feat: 修改个人信息、接口
|
3
|
import 'package:wow_english/common/core/user_util.dart';
|
c95453ce
Key
feat: User界面完善
|
4
|
import 'package:wow_english/common/request/dao/user_dao.dart';
|
c9df43c8
Key
feat: 修改个人信息、接口
|
5
6
7
|
import 'package:wow_english/models/user_entity.dart';
import 'package:wow_english/pages/user/modify/modify_user_information_page.dart';
import 'package:wow_english/utils/log_util.dart';
|
22b7d4da
Key
feat: user, api path
|
8
9
10
11
12
|
part 'user_event.dart';
part 'user_state.dart';
class UserBloc extends Bloc<UserEvent, UserState> {
|
c9df43c8
Key
feat: 修改个人信息、接口
|
13
|
final TextEditingController modifyTextController = TextEditingController();
|
01e73e19
Key
暂时关闭修改个人信息
|
14
|
int tempGender = 0;
|
c9df43c8
Key
feat: 修改个人信息、接口
|
15
|
|
22b7d4da
Key
feat: user, api path
|
16
|
UserBloc() : super(UserInitial()) {
|
c61b3c1a
Key
feat: toast_util....
|
17
|
on<UserLogout>(_logout);
|
a4d8eaa2
Key
feat: 登录时账户有效性校验
|
18
|
on<UserDelete>(_deleteAccount);
|
c9df43c8
Key
feat: 修改个人信息、接口
|
19
|
on<UserUpdate>(_updateUser);
|
01e73e19
Key
暂时关闭修改个人信息
|
20
|
on<UserUIUpdate>(_updateUIUser);
|
22b7d4da
Key
feat: user, api path
|
21
|
}
|
c95453ce
Key
feat: User界面完善
|
22
|
|
c61b3c1a
Key
feat: toast_util....
|
23
|
void _logout(UserLogout event, Emitter<UserState> emitter) async {
|
c95453ce
Key
feat: User界面完善
|
24
25
|
await UserDao.logout();
}
|
c9df43c8
Key
feat: 修改个人信息、接口
|
26
|
|
a4d8eaa2
Key
feat: 登录时账户有效性校验
|
27
28
29
30
|
void _deleteAccount(UserDelete event, Emitter<UserState> emitter) async {
await UserDao.deleteAccount();
}
|
01e73e19
Key
暂时关闭修改个人信息
|
31
32
33
34
|
void _updateUIUser(UserUIUpdate event, Emitter<UserState> emitter) async {
emitter(UserInfoUpdated());
}
|
c9df43c8
Key
feat: 修改个人信息、接口
|
35
36
37
38
39
40
41
42
|
void _updateUser(UserUpdate event, Emitter<UserState> emitter) async {
Log.d('_updateUser, event: ${event.type}, emitter.isDone: ${emitter.isDone}, text=${modifyTextController.text}');
UserEntity user = UserUtil.getUser()!;
switch (event.type) {
case ModifyUserInformationType.avatar:
break;
case ModifyUserInformationType.name:
String name = modifyTextController.text;
|
c9df43c8
Key
feat: 修改个人信息、接口
|
43
|
try {
|
e6a4e63c
Key
fixed: 修改个人信息性别
|
44
45
46
|
await UserDao.updateUserInfoField(name: name);
// 修改成功,更新本地缓存及UI
user.name = name;
|
c9df43c8
Key
feat: 修改个人信息、接口
|
47
48
|
emitter(UserInfoUpdated());
} catch (e) {
|
e6a4e63c
Key
fixed: 修改个人信息性别
|
49
|
Log.e('_updateUser name, e: $e');
|
c9df43c8
Key
feat: 修改个人信息、接口
|
50
51
52
|
}
break;
case ModifyUserInformationType.age:
|
e6a4e63c
Key
fixed: 修改个人信息性别
|
53
|
// todo 校验格式
|
e6a4e63c
Key
fixed: 修改个人信息性别
|
54
|
try {
|
01e73e19
Key
暂时关闭修改个人信息
|
55
56
57
58
59
60
61
|
int age;
try {
age = modifyTextController.text as int;
} catch (e) {
Log.w(e.toString());
throw '年龄格式错误';
}
|
e6a4e63c
Key
fixed: 修改个人信息性别
|
62
63
64
65
66
67
68
|
await UserDao.updateUserInfoField(age: age);
// 修改成功,更新本地缓存及UI
user.age = age;
emitter(UserInfoUpdated());
} catch (e) {
Log.e('_updateUser age, e: $e');
}
|
c9df43c8
Key
feat: 修改个人信息、接口
|
69
70
|
break;
case ModifyUserInformationType.gender:
|
e6a4e63c
Key
fixed: 修改个人信息性别
|
71
|
try {
|
01e73e19
Key
暂时关闭修改个人信息
|
72
73
|
await UserDao.updateUserInfoField(gender: tempGender);
user.gender = tempGender;
|
e6a4e63c
Key
fixed: 修改个人信息性别
|
74
75
|
emitter(UserInfoUpdated());
} catch (e) {
|
01e73e19
Key
暂时关闭修改个人信息
|
76
|
Log.e('_updateUser gender, e: $e');
|
e6a4e63c
Key
fixed: 修改个人信息性别
|
77
|
}
|
c9df43c8
Key
feat: 修改个人信息、接口
|
78
79
80
|
break;
}
}
|
22b7d4da
Key
feat: user, api path
|
81
|
}
|