Commit e6a4e63c7db07007e3b57e9ac3bf524b83200861
1 parent
d4a7dfc4
fixed: 修改个人信息性别
Showing
7 changed files
with
97 additions
and
20 deletions
lib/common/core/app_consts.dart
| 1 | 1 | class AppConsts { |
| 2 | 2 | /// 隐私协议 |
| 3 | - static const String userPrivacyPolicyUrl = | |
| 4 | - 'http://page.kouyuxingqiu.com/%E7%94%A8%E6%88%B7%E6%B3%A8%E5%86%8C%E5%8F%8A%E4%BD%BF%E7%94%A8APP%E9%9A%90%E7%A7%81%E5%8D%8F%E8%AE%AE.html'; | |
| 3 | + static const String userPrivacyPolicyUrl = 'http://page.kouyuxingqiu.com/wowenglishuserregister.html'; | |
| 5 | 4 | |
| 6 | 5 | /// 儿童隐私协议 |
| 7 | - static const String childrenPrivacyPolicyUrl = | |
| 8 | - 'https://ishowedu-public-images.ishowedu.com/%E5%8F%A3%E8%AF%AD%E6%98%9F%E7%90%83%E5%84%BF%E7%AB%A5%E9%9A%90%E7%A7%81%E4%BF%9D%E6%8A%A4%E6%94%BF%E7%AD%96_iShowLD%E4%BF%AE%E8%AE%A2_20210913%281%29.html'; | |
| 6 | + static const String childrenPrivacyPolicyUrl = 'http://page.kouyuxingqiu.com/wowenglishchildprotect.html'; | |
| 9 | 7 | |
| 10 | 8 | /// 与第三方共享协议 |
| 11 | 9 | static const String userTermSdkUrl = 'http://page.kouyuxingqiu.com/term_sdk.html'; | ... | ... |
lib/common/core/assets_const.dart
| ... | ... | @@ -5,6 +5,7 @@ class AssetsConst { |
| 5 | 5 | static const String icNext = '${_assetImagePrefix}ic_next.png'; |
| 6 | 6 | static const String bgUserInformationText = '${_assetImagePrefix}bg_user_information_text.png'; |
| 7 | 7 | static const String bgEditUserInformation = '${_assetImagePrefix}bg_edit_information.png'; |
| 8 | + static const String bgIcSteveWrite = '${_assetImagePrefix}bg_steve_write.png'; | |
| 8 | 9 | static const String bgButtonBlue = '${_assetImagePrefix}bg_button_blue.png'; |
| 9 | 10 | static const String bgButtonBlueAccent = '${_assetImagePrefix}bg_button_blue_accent.png'; |
| 10 | 11 | //static String get icVip2 =>'ic_vip.png'.assetImg; | ... | ... |
lib/common/request/dao/user_dao.dart
| 1 | 1 | import 'package:wow_english/common/core/user_util.dart'; |
| 2 | 2 | import 'package:wow_english/models/user_entity.dart'; |
| 3 | +import 'package:wow_english/utils/log_util.dart'; | |
| 3 | 4 | |
| 4 | 5 | import '../request_client.dart'; |
| 5 | 6 | |
| ... | ... | @@ -73,6 +74,24 @@ class UserDao { |
| 73 | 74 | |
| 74 | 75 | /// 更新用户信息,返回即成功,无body |
| 75 | 76 | static Future updateUserInfo(UserEntity userEntity) async { |
| 77 | + Log.d('updateUserInfo, userEntity: $userEntity'); | |
| 76 | 78 | return await requestClient.put(Apis.setUserInfo, data: userEntity.toUpdateJson()); |
| 77 | 79 | } |
| 80 | + | |
| 81 | + static Future updateUserInfoField({name, age, gender, avatarUrl}) async { | |
| 82 | + final Map<String, dynamic> data = <String, dynamic>{}; | |
| 83 | + if (name != null) { | |
| 84 | + data['name'] = name; | |
| 85 | + } | |
| 86 | + if (age != null) { | |
| 87 | + data['age'] = age; | |
| 88 | + } | |
| 89 | + if (gender != null) { | |
| 90 | + data['gender'] = gender; | |
| 91 | + } | |
| 92 | + if (avatarUrl != null) { | |
| 93 | + data['avatarUrl'] = avatarUrl; | |
| 94 | + } | |
| 95 | + return await requestClient.put(Apis.setUserInfo, data: data); | |
| 96 | + } | |
| 78 | 97 | } | ... | ... |
lib/common/widgets/textfield_customer_widget.dart
| ... | ... | @@ -48,9 +48,9 @@ class _TextFieldCustomerWidgetState extends State<TextFieldCustomerWidget> { |
| 48 | 48 | alignment: Alignment.center, |
| 49 | 49 | decoration: BoxDecoration( |
| 50 | 50 | image: DecorationImage( |
| 51 | - image: AssetImage('${widget.bgImageName}'.assetPng), | |
| 52 | - fit: BoxFit.fill, | |
| 53 | - )), | |
| 51 | + image: AssetImage('${widget.bgImageName}'.assetPng), | |
| 52 | + fit: BoxFit.fill, | |
| 53 | + )), | |
| 54 | 54 | child: TextField( |
| 55 | 55 | inputFormatters: widget.inputFormatters, |
| 56 | 56 | controller: widget.controller, | ... | ... |
lib/pages/login/loginpage/login_page.dart
| ... | ... | @@ -116,8 +116,7 @@ class _LoginPageView extends StatelessWidget { |
| 116 | 116 | recognizer: TapGestureRecognizer() |
| 117 | 117 | ..onTap = () { |
| 118 | 118 | Navigator.of(context).pushNamed(AppRouteName.webView, arguments: { |
| 119 | - 'urlStr': | |
| 120 | - 'https://ishowedu-public-images.ishowedu.com/%E5%8F%A3%E8%AF%AD%E6%98%9F%E7%90%83%E5%84%BF%E7%AB%A5%E9%9A%90%E7%A7%81%E4%BF%9D%E6%8A%A4%E6%94%BF%E7%AD%96_iShowLD%E4%BF%AE%E8%AE%A2_20210913%281%29.html', | |
| 119 | + 'urlStr': AppConsts.childrenPrivacyPolicyUrl, | |
| 121 | 120 | 'webViewTitle': '儿童隐私协议' |
| 122 | 121 | }); |
| 123 | 122 | }) | ... | ... |
lib/pages/user/bloc/user_bloc.dart
| ... | ... | @@ -29,18 +29,34 @@ class UserBloc extends Bloc<UserEvent, UserState> { |
| 29 | 29 | break; |
| 30 | 30 | case ModifyUserInformationType.name: |
| 31 | 31 | String name = modifyTextController.text; |
| 32 | - user.name = name; | |
| 33 | 32 | try { |
| 34 | - await UserDao.updateUserInfo(user); | |
| 33 | + await UserDao.updateUserInfoField(name: name); | |
| 34 | + // 修改成功,更新本地缓存及UI | |
| 35 | + user.name = name; | |
| 35 | 36 | emitter(UserInfoUpdated()); |
| 36 | 37 | } catch (e) { |
| 37 | - print(e); | |
| 38 | + Log.e('_updateUser name, e: $e'); | |
| 38 | 39 | } |
| 39 | 40 | break; |
| 40 | 41 | case ModifyUserInformationType.age: |
| 41 | - String age = modifyTextController.text; | |
| 42 | + // todo 校验格式 | |
| 43 | + int age = modifyTextController.text as int; | |
| 44 | + try { | |
| 45 | + await UserDao.updateUserInfoField(age: age); | |
| 46 | + // 修改成功,更新本地缓存及UI | |
| 47 | + user.age = age; | |
| 48 | + emitter(UserInfoUpdated()); | |
| 49 | + } catch (e) { | |
| 50 | + Log.e('_updateUser age, e: $e'); | |
| 51 | + } | |
| 42 | 52 | break; |
| 43 | 53 | case ModifyUserInformationType.gender: |
| 54 | + try { | |
| 55 | + await UserDao.updateUserInfoField(gender: user.gender); | |
| 56 | + emitter(UserInfoUpdated()); | |
| 57 | + } catch (e) { | |
| 58 | + Log.e('_updateUser age, e: $e'); | |
| 59 | + } | |
| 44 | 60 | break; |
| 45 | 61 | } |
| 46 | 62 | } | ... | ... |
lib/pages/user/modify/modify_user_information_page.dart
| ... | ... | @@ -4,6 +4,7 @@ import 'package:flutter/services.dart'; |
| 4 | 4 | import 'package:flutter_bloc/flutter_bloc.dart'; |
| 5 | 5 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
| 6 | 6 | import 'package:wow_english/common/core/assets_const.dart'; |
| 7 | +import 'package:wow_english/common/core/user_util.dart'; | |
| 7 | 8 | import 'package:wow_english/common/widgets/textfield_customer_widget.dart'; |
| 8 | 9 | import 'package:wow_english/common/widgets/we_app_bar.dart'; |
| 9 | 10 | import 'package:wow_english/pages/user/bloc/user_bloc.dart'; |
| ... | ... | @@ -89,6 +90,20 @@ class ModifyUserInformationPage extends StatelessWidget { |
| 89 | 90 | ) |
| 90 | 91 | ], |
| 91 | 92 | )), |
| 93 | + Stack( | |
| 94 | + alignment: Alignment.topRight, | |
| 95 | + children: [ | |
| 96 | + Image.asset( | |
| 97 | + AssetsConst.bgEditUserInformation, | |
| 98 | + width: double.infinity, | |
| 99 | + ), | |
| 100 | + Positioned( | |
| 101 | + right: 125.w, | |
| 102 | + top: 10.h, | |
| 103 | + child: Image.asset(AssetsConst.bgIcSteveWrite, width: 161.w, height: 249.w), | |
| 104 | + ), | |
| 105 | + ], | |
| 106 | + ), | |
| 92 | 107 | ], |
| 93 | 108 | )); |
| 94 | 109 | }), |
| ... | ... | @@ -98,28 +113,51 @@ class ModifyUserInformationPage extends StatelessWidget { |
| 98 | 113 | } |
| 99 | 114 | |
| 100 | 115 | Widget _buildTextFieldWidget(BuildContext context) { |
| 116 | + var userBloc = context.read<UserBloc>(); | |
| 117 | + var user = UserUtil.getUser()!; | |
| 118 | + Log.d('user = $user'); | |
| 101 | 119 | if (type == ModifyUserInformationType.gender) { |
| 102 | 120 | return Row( |
| 103 | 121 | children: <Widget>[ |
| 104 | 122 | SizedBox( |
| 105 | - width: 150, | |
| 123 | + width: 100.w, | |
| 106 | 124 | child: RadioListTile( |
| 107 | - title: const Text('男'), | |
| 125 | + title: Text( | |
| 126 | + '男', | |
| 127 | + style: TextStyle( | |
| 128 | + fontWeight: FontWeight.w700, | |
| 129 | + color: const Color(0xFF333333), | |
| 130 | + fontSize: 21.sp, | |
| 131 | + ), | |
| 132 | + ), | |
| 133 | + activeColor: const Color(0xFF0E89BA), | |
| 108 | 134 | value: 0, |
| 109 | - groupValue: type, | |
| 135 | + //selected: user.gender == 0, | |
| 136 | + groupValue: user.gender, | |
| 110 | 137 | onChanged: (value) { |
| 111 | 138 | Log.d('男value = $value'); |
| 139 | + user.gender = value as int; | |
| 112 | 140 | }, |
| 113 | 141 | ), |
| 114 | 142 | ), |
| 115 | 143 | SizedBox( |
| 116 | - width: 150, | |
| 144 | + width: 100.w, | |
| 117 | 145 | child: RadioListTile( |
| 118 | - title: const Text('女'), | |
| 146 | + //selected: user.gender == 1, | |
| 147 | + title: Text( | |
| 148 | + '女', | |
| 149 | + style: TextStyle( | |
| 150 | + fontWeight: FontWeight.w700, | |
| 151 | + color: const Color(0xFF333333), | |
| 152 | + fontSize: 21.sp, | |
| 153 | + ), | |
| 154 | + ), | |
| 155 | + activeColor: const Color(0xFF0E89BA), | |
| 119 | 156 | value: 1, |
| 120 | - groupValue: type, | |
| 157 | + groupValue: user.gender, | |
| 121 | 158 | onChanged: (value) { |
| 122 | 159 | Log.d('女value = $value'); |
| 160 | + user.gender = value as int; | |
| 123 | 161 | }, |
| 124 | 162 | ), |
| 125 | 163 | ), |
| ... | ... | @@ -140,13 +178,19 @@ class ModifyUserInformationPage extends StatelessWidget { |
| 140 | 178 | ]; |
| 141 | 179 | inputType = TextInputType.number; |
| 142 | 180 | } |
| 181 | + | |
| 143 | 182 | return TextFieldCustomerWidget( |
| 144 | 183 | height: 65.h, |
| 145 | 184 | width: 222.w, |
| 185 | + textStyle: TextStyle( | |
| 186 | + fontWeight: FontWeight.w700, | |
| 187 | + color: const Color(0xFF333333), | |
| 188 | + fontSize: 21.sp, | |
| 189 | + ), | |
| 146 | 190 | bgImageName: 'Input_layer_up', |
| 147 | 191 | textInputType: inputType, |
| 148 | 192 | inputFormatters: formatters, |
| 149 | - controller: context.read<UserBloc>().modifyTextController, | |
| 193 | + controller: userBloc.modifyTextController, | |
| 150 | 194 | /*onChangeValue: (String value) { |
| 151 | 195 | bloc.add(CodeNumberChangeEvent()); |
| 152 | 196 | },*/ | ... | ... |