From 23b46e8e3df0e20a602108774441890d4be680a0 Mon Sep 17 00:00:00 2001 From: Key Date: Sun, 2 Jul 2023 17:24:55 +0800 Subject: [PATCH] feat: 修改个人信息性别 --- lib/models/user_entity.dart | 2 +- lib/pages/user/information/user_information_page.dart | 6 ++++-- lib/pages/user/modify/modify_user_avatar_page.dart | 0 lib/pages/user/modify/modify_user_information_page.dart | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------- 4 files changed, 61 insertions(+), 20 deletions(-) create mode 100644 lib/pages/user/modify/modify_user_avatar_page.dart diff --git a/lib/models/user_entity.dart b/lib/models/user_entity.dart index e165c25..674ea0b 100644 --- a/lib/models/user_entity.dart +++ b/lib/models/user_entity.dart @@ -15,7 +15,7 @@ class UserEntity { int? age; - /// 性别:0, 1 + /// 性别:0男, 1女 int? gender; String? avatarUrl; late String phoneNum; diff --git a/lib/pages/user/information/user_information_page.dart b/lib/pages/user/information/user_information_page.dart index dccb2dd..e90fc78 100644 --- a/lib/pages/user/information/user_information_page.dart +++ b/lib/pages/user/information/user_information_page.dart @@ -91,7 +91,8 @@ class _UserInformationContentView extends StatelessWidget { color: const Color(0xFF333333), fontSize: 21.sp, ), - )), + ), + onTap: () => _openModifyPage(context, ModifyUserInformationType.age)), 11.verticalSpace, _buildContentRow( '性别', @@ -102,7 +103,8 @@ class _UserInformationContentView extends StatelessWidget { color: const Color(0xFF333333), fontSize: 21.sp, ), - )), + ), + onTap: () => _openModifyPage(context, ModifyUserInformationType.gender)), 11.verticalSpace, _buildContentRow( '账号', diff --git a/lib/pages/user/modify/modify_user_avatar_page.dart b/lib/pages/user/modify/modify_user_avatar_page.dart new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/lib/pages/user/modify/modify_user_avatar_page.dart diff --git a/lib/pages/user/modify/modify_user_information_page.dart b/lib/pages/user/modify/modify_user_information_page.dart index b495ff8..a4c1ae0 100644 --- a/lib/pages/user/modify/modify_user_information_page.dart +++ b/lib/pages/user/modify/modify_user_information_page.dart @@ -7,6 +7,7 @@ import 'package:wow_english/common/core/assets_const.dart'; import 'package:wow_english/common/widgets/textfield_customer_widget.dart'; import 'package:wow_english/common/widgets/we_app_bar.dart'; import 'package:wow_english/pages/user/bloc/user_bloc.dart'; +import 'package:wow_english/utils/log_util.dart'; enum ModifyUserInformationType { avatar('头像'), @@ -40,8 +41,7 @@ class ModifyUserInformationPage extends StatelessWidget { titleText: '修改${type.title}', ), body: BlocListener( - listener: (context, state) { - }, + listener: (context, state) {}, child: BlocBuilder(builder: (context, state) { //final bloc = context.read(); // 区别是什么? @@ -62,20 +62,9 @@ class ModifyUserInformationPage extends StatelessWidget { ), ), 20.horizontalSpace, - TextFieldCustomerWidget( - height: 65.h, - width: 222.w, - bgImageName: 'Input_layer_up', - textInputType: TextInputType.name, - inputFormatters: [ - LengthLimitingTextInputFormatter(12), - FilteringTextInputFormatter.deny(RegExp('[ ]')), - ], - //controller: bloc.modifyTextController, - /*onChangeValue: (String value) { - bloc.add(CodeNumberChangeEvent()); - },*/ - ), + // 输入框 or 选择框 + _buildTextFieldWidget(context), + // 占位 Expanded( child: Container(), ), @@ -83,7 +72,7 @@ class ModifyUserInformationPage extends StatelessWidget { GestureDetector( onTap: () { // 更新type类型的字段 - //bloc.add(UserUpdate(type)); + context.read().add(UserUpdate(type)); }, child: Container( alignment: Alignment.center, @@ -107,4 +96,54 @@ class ModifyUserInformationPage extends StatelessWidget { ), ); } + + Widget _buildTextFieldWidget(BuildContext context) { + if (type == ModifyUserInformationType.gender) { + return Row( + children: [ + RadioListTile( + title: const Text('男'), + value: 0, + groupValue: type, + onChanged: (value) { + Log.d('男value = $value'); + }, + ), + RadioListTile( + title: const Text('女'), + value: 1, + groupValue: type, + onChanged: (value) { + Log.d('女value = $value'); + }, + ), + ], + ); + } + + var formatters = [ + LengthLimitingTextInputFormatter(12), + FilteringTextInputFormatter.deny(RegExp('[ ]')), + ]; + var inputType = TextInputType.name; + // 当输入年龄时 + if (type == ModifyUserInformationType.age) { + formatters = [ + LengthLimitingTextInputFormatter(2), + FilteringTextInputFormatter.deny(RegExp('[ ]')), + ]; + inputType = TextInputType.number; + } + return TextFieldCustomerWidget( + height: 65.h, + width: 222.w, + bgImageName: 'Input_layer_up', + textInputType: inputType, + inputFormatters: formatters, + controller: context.read().modifyTextController, + /*onChangeValue: (String value) { + bloc.add(CodeNumberChangeEvent()); + },*/ + ); + } } -- libgit2 0.22.2