Commit 01e73e1919b18e3244bc777df384ca12e48bb3d7
1 parent
e6a4e63c
暂时关闭修改个人信息
Showing
6 changed files
with
46 additions
and
12 deletions
lib/common/request/config.dart
1 | +import 'package:flutter/foundation.dart'; | ||
2 | + | ||
1 | ///request config | 3 | ///request config |
2 | class RequestConfig { | 4 | class RequestConfig { |
3 | - static String baseUrl = 'http://wow-app.dev.kouyuxingqiu.com/'; | 5 | + static String baseUrlDev = 'http://wow-app.dev.kouyuxingqiu.com/'; |
6 | + static String baseUrlProd = 'http://app-api.pro.kouyuxingqiu.com/'; | ||
7 | + static String baseUrl = kDebugMode ? baseUrlDev : baseUrlProd; | ||
8 | + | ||
4 | static const connectTimeout = Duration(seconds: 15); | 9 | static const connectTimeout = Duration(seconds: 15); |
5 | static const successCode = 200; | 10 | static const successCode = 200; |
6 | } | 11 | } |
lib/common/request/dao/user_dao.dart
@@ -78,7 +78,9 @@ class UserDao { | @@ -78,7 +78,9 @@ class UserDao { | ||
78 | return await requestClient.put(Apis.setUserInfo, data: userEntity.toUpdateJson()); | 78 | return await requestClient.put(Apis.setUserInfo, data: userEntity.toUpdateJson()); |
79 | } | 79 | } |
80 | 80 | ||
81 | - static Future updateUserInfoField({name, age, gender, avatarUrl}) async { | 81 | + /// 更新用户信息指定字段 |
82 | + static Future updateUserInfoField({String? name, int? age, int? gender, String? avatarUrl}) async { | ||
83 | + Log.d('name=$name, age=$age, gender=$gender, avatarUrl=$avatarUrl'); | ||
82 | final Map<String, dynamic> data = <String, dynamic>{}; | 84 | final Map<String, dynamic> data = <String, dynamic>{}; |
83 | if (name != null) { | 85 | if (name != null) { |
84 | data['name'] = name; | 86 | data['name'] = name; |
lib/pages/user/bloc/user_bloc.dart
@@ -11,16 +11,22 @@ part 'user_state.dart'; | @@ -11,16 +11,22 @@ part 'user_state.dart'; | ||
11 | 11 | ||
12 | class UserBloc extends Bloc<UserEvent, UserState> { | 12 | class UserBloc extends Bloc<UserEvent, UserState> { |
13 | final TextEditingController modifyTextController = TextEditingController(); | 13 | final TextEditingController modifyTextController = TextEditingController(); |
14 | + int tempGender = 0; | ||
14 | 15 | ||
15 | UserBloc() : super(UserInitial()) { | 16 | UserBloc() : super(UserInitial()) { |
16 | on<UserLogout>(_logout); | 17 | on<UserLogout>(_logout); |
17 | on<UserUpdate>(_updateUser); | 18 | on<UserUpdate>(_updateUser); |
19 | + on<UserUIUpdate>(_updateUIUser); | ||
18 | } | 20 | } |
19 | 21 | ||
20 | void _logout(UserLogout event, Emitter<UserState> emitter) async { | 22 | void _logout(UserLogout event, Emitter<UserState> emitter) async { |
21 | await UserDao.logout(); | 23 | await UserDao.logout(); |
22 | } | 24 | } |
23 | 25 | ||
26 | + void _updateUIUser(UserUIUpdate event, Emitter<UserState> emitter) async { | ||
27 | + emitter(UserInfoUpdated()); | ||
28 | + } | ||
29 | + | ||
24 | void _updateUser(UserUpdate event, Emitter<UserState> emitter) async { | 30 | void _updateUser(UserUpdate event, Emitter<UserState> emitter) async { |
25 | Log.d('_updateUser, event: ${event.type}, emitter.isDone: ${emitter.isDone}, text=${modifyTextController.text}'); | 31 | Log.d('_updateUser, event: ${event.type}, emitter.isDone: ${emitter.isDone}, text=${modifyTextController.text}'); |
26 | UserEntity user = UserUtil.getUser()!; | 32 | UserEntity user = UserUtil.getUser()!; |
@@ -40,8 +46,14 @@ class UserBloc extends Bloc<UserEvent, UserState> { | @@ -40,8 +46,14 @@ class UserBloc extends Bloc<UserEvent, UserState> { | ||
40 | break; | 46 | break; |
41 | case ModifyUserInformationType.age: | 47 | case ModifyUserInformationType.age: |
42 | // todo 校验格式 | 48 | // todo 校验格式 |
43 | - int age = modifyTextController.text as int; | ||
44 | try { | 49 | try { |
50 | + int age; | ||
51 | + try { | ||
52 | + age = modifyTextController.text as int; | ||
53 | + } catch (e) { | ||
54 | + Log.w(e.toString()); | ||
55 | + throw '年龄格式错误'; | ||
56 | + } | ||
45 | await UserDao.updateUserInfoField(age: age); | 57 | await UserDao.updateUserInfoField(age: age); |
46 | // 修改成功,更新本地缓存及UI | 58 | // 修改成功,更新本地缓存及UI |
47 | user.age = age; | 59 | user.age = age; |
@@ -52,10 +64,11 @@ class UserBloc extends Bloc<UserEvent, UserState> { | @@ -52,10 +64,11 @@ class UserBloc extends Bloc<UserEvent, UserState> { | ||
52 | break; | 64 | break; |
53 | case ModifyUserInformationType.gender: | 65 | case ModifyUserInformationType.gender: |
54 | try { | 66 | try { |
55 | - await UserDao.updateUserInfoField(gender: user.gender); | 67 | + await UserDao.updateUserInfoField(gender: tempGender); |
68 | + user.gender = tempGender; | ||
56 | emitter(UserInfoUpdated()); | 69 | emitter(UserInfoUpdated()); |
57 | } catch (e) { | 70 | } catch (e) { |
58 | - Log.e('_updateUser age, e: $e'); | 71 | + Log.e('_updateUser gender, e: $e'); |
59 | } | 72 | } |
60 | break; | 73 | break; |
61 | } | 74 | } |
lib/pages/user/bloc/user_event.dart
@@ -11,3 +11,9 @@ class UserUpdate extends UserEvent { | @@ -11,3 +11,9 @@ class UserUpdate extends UserEvent { | ||
11 | 11 | ||
12 | UserUpdate(this.type); | 12 | UserUpdate(this.type); |
13 | } | 13 | } |
14 | + | ||
15 | +class UserUIUpdate extends UserEvent { | ||
16 | + final ModifyUserInformationType type; | ||
17 | + | ||
18 | + UserUIUpdate(this.type); | ||
19 | +} |
lib/pages/user/information/user_information_page.dart
@@ -44,7 +44,8 @@ class _UserInformationContentView extends StatelessWidget { | @@ -44,7 +44,8 @@ class _UserInformationContentView extends StatelessWidget { | ||
44 | 44 | ||
45 | void _openModifyPage(BuildContext context, ModifyUserInformationType type) { | 45 | void _openModifyPage(BuildContext context, ModifyUserInformationType type) { |
46 | Log.d('_openModifyPage($type)'); | 46 | Log.d('_openModifyPage($type)'); |
47 | - ModifyUserInformationPage.push(context, type); | 47 | + // 暂时关闭修改,修复后打开 |
48 | + //ModifyUserInformationPage.push(context, type); | ||
48 | } | 49 | } |
49 | 50 | ||
50 | @override | 51 | @override |
lib/pages/user/modify/modify_user_information_page.dart
@@ -115,6 +115,7 @@ class ModifyUserInformationPage extends StatelessWidget { | @@ -115,6 +115,7 @@ class ModifyUserInformationPage extends StatelessWidget { | ||
115 | Widget _buildTextFieldWidget(BuildContext context) { | 115 | Widget _buildTextFieldWidget(BuildContext context) { |
116 | var userBloc = context.read<UserBloc>(); | 116 | var userBloc = context.read<UserBloc>(); |
117 | var user = UserUtil.getUser()!; | 117 | var user = UserUtil.getUser()!; |
118 | + userBloc.tempGender = user.gender ?? 0; | ||
118 | Log.d('user = $user'); | 119 | Log.d('user = $user'); |
119 | if (type == ModifyUserInformationType.gender) { | 120 | if (type == ModifyUserInformationType.gender) { |
120 | return Row( | 121 | return Row( |
@@ -133,16 +134,19 @@ class ModifyUserInformationPage extends StatelessWidget { | @@ -133,16 +134,19 @@ class ModifyUserInformationPage extends StatelessWidget { | ||
133 | activeColor: const Color(0xFF0E89BA), | 134 | activeColor: const Color(0xFF0E89BA), |
134 | value: 0, | 135 | value: 0, |
135 | //selected: user.gender == 0, | 136 | //selected: user.gender == 0, |
136 | - groupValue: user.gender, | 137 | + groupValue: userBloc.tempGender, |
137 | onChanged: (value) { | 138 | onChanged: (value) { |
138 | Log.d('男value = $value'); | 139 | Log.d('男value = $value'); |
139 | - user.gender = value as int; | 140 | + if (value != null) { |
141 | + userBloc.tempGender = value; | ||
142 | + } | ||
143 | + userBloc.add(UserUIUpdate(type)); | ||
140 | }, | 144 | }, |
141 | ), | 145 | ), |
142 | ), | 146 | ), |
143 | SizedBox( | 147 | SizedBox( |
144 | width: 100.w, | 148 | width: 100.w, |
145 | - child: RadioListTile( | 149 | + child: RadioListTile<int>( |
146 | //selected: user.gender == 1, | 150 | //selected: user.gender == 1, |
147 | title: Text( | 151 | title: Text( |
148 | '女', | 152 | '女', |
@@ -154,10 +158,13 @@ class ModifyUserInformationPage extends StatelessWidget { | @@ -154,10 +158,13 @@ class ModifyUserInformationPage extends StatelessWidget { | ||
154 | ), | 158 | ), |
155 | activeColor: const Color(0xFF0E89BA), | 159 | activeColor: const Color(0xFF0E89BA), |
156 | value: 1, | 160 | value: 1, |
157 | - groupValue: user.gender, | ||
158 | - onChanged: (value) { | 161 | + groupValue: userBloc.tempGender, |
162 | + onChanged: (int? value) { | ||
159 | Log.d('女value = $value'); | 163 | Log.d('女value = $value'); |
160 | - user.gender = value as int; | 164 | + if (value != null) { |
165 | + userBloc.tempGender = value; | ||
166 | + } | ||
167 | + userBloc.add(UserUIUpdate(type)); | ||
161 | }, | 168 | }, |
162 | ), | 169 | ), |
163 | ), | 170 | ), |