diff --git a/lib/pages/user/information/user_information_page.dart b/lib/pages/user/information/user_information_page.dart index 1130638..0cca512 100644 --- a/lib/pages/user/information/user_information_page.dart +++ b/lib/pages/user/information/user_information_page.dart @@ -17,16 +17,13 @@ class UserInformationPage extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context,state){ - return _UserInformationContentView(); - }); + return BlocBuilder(builder: (context, state) { + return _UserInformationContentView(); + }); } } - class _UserInformationContentView extends StatelessWidget { - void _openModifyPage(BuildContext context, ModifyUserInformationType type) { Log.d('_openModifyPage($type)'); ModifyUserInformationPage.push(context, type); @@ -41,7 +38,8 @@ class _UserInformationContentView extends StatelessWidget { titleText: "个人信息", ), body: SingleChildScrollView( - padding: EdgeInsets.only(left: 17.w, right: 17.w, top: 10.h, bottom: 22.h), + padding: + EdgeInsets.only(left: 17.w, right: 17.w, top: 10.h, bottom: 22.h), child: Column( children: [ _buildContentRow( @@ -51,11 +49,12 @@ class _UserInformationContentView extends StatelessWidget { backgroundColor: const Color(0xFF140C10), child: CircleAvatar( radius: 21.r, - backgroundImage: ImageUtil.getImageProviderOnDefault(user.avatarUrl), + backgroundImage: + ImageUtil.getImageProviderOnDefault(user.avatarUrl), ), ), - onTap: () => pushNamed(AppRouteName.userAvatar,arguments: {'pageType':'1'}) - ), + onTap: () => pushNamed(AppRouteName.userAvatar, + arguments: {'pageType': '1'})), 11.verticalSpace, _buildContentRow( '名字', @@ -67,19 +66,21 @@ class _UserInformationContentView extends StatelessWidget { fontSize: 21.sp, ), ), - onTap: () => _openModifyPage(context, ModifyUserInformationType.name)), + onTap: () => + _openModifyPage(context, ModifyUserInformationType.name)), 11.verticalSpace, _buildContentRow( '年龄', Text( - (user.age??0).toString(), + (user.age ?? 0).toString(), style: TextStyle( fontWeight: FontWeight.w500, color: const Color(0xFF333333), fontSize: 21.sp, ), ), - onTap: () => _openModifyPage(context, ModifyUserInformationType.age)), + onTap: () => + _openModifyPage(context, ModifyUserInformationType.age)), 11.verticalSpace, _buildContentRow( '性别', @@ -91,7 +92,8 @@ class _UserInformationContentView extends StatelessWidget { fontSize: 21.sp, ), ), - onTap: () => _openModifyPage(context, ModifyUserInformationType.gender)), + onTap: () => + _openModifyPage(context, ModifyUserInformationType.gender)), 11.verticalSpace, _buildContentRow( '账号', @@ -111,14 +113,18 @@ class _UserInformationContentView extends StatelessWidget { ); } - Widget _buildContentRow(String filedName, Widget contentWidget, {bool isHideEndIcon = false, Function()? onTap}) { + Widget _buildContentRow(String filedName, Widget contentWidget, + {bool isHideEndIcon = false, Function()? onTap}) { return GestureDetector( onTap: onTap, child: Container( - padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 18.h, bottom: 18.h), + padding: + EdgeInsets.only(left: 16.w, right: 16.w, top: 18.h, bottom: 18.h), decoration: BoxDecoration( image: DecorationImage( - image: ImageUtil.getImageProviderOnDefault(AssetsConst.bgUserInformationText), fit: BoxFit.fill)), + image: ImageUtil.getImageProviderOnDefault( + AssetsConst.bgUserInformationText), + fit: BoxFit.fill)), child: Row(children: [ Text( filedName, @@ -131,9 +137,9 @@ class _UserInformationContentView extends StatelessWidget { 32.horizontalSpace, Expanded( child: Container( - alignment: Alignment.centerLeft, - child: contentWidget, - )), + alignment: Alignment.centerLeft, + child: contentWidget, + )), Offstage( offstage: isHideEndIcon, child: Image.asset(AssetsConst.icNext, width: 20.w, height: 25.h), diff --git a/lib/pages/user/modify/modify_user_information_page.dart b/lib/pages/user/modify/modify_user_information_page.dart index 3c17024..5601bd6 100644 --- a/lib/pages/user/modify/modify_user_information_page.dart +++ b/lib/pages/user/modify/modify_user_information_page.dart @@ -47,7 +47,7 @@ class ModifyUserInformationPage extends StatelessWidget { create: (context) => UserInfoBloc()..add(InitControllerTextEvent(text)), child: MultiBlocListener( listeners: [ - BlocListener(listener: (context, state){ + BlocListener(listener: (context, state) { if (state is UserInfoUpdated) { showToast('修改成功'); popPage(); @@ -64,9 +64,11 @@ class ModifyUserInformationPage extends StatelessWidget { onBack: () { final bloc = BlocProvider.of(context); if (bloc.isChangeInfo) { - showTwoActionDialog('提示', '确定离开', '继续修改', '您的信息尚未保存',leftTap: (){ + showTwoActionDialog('提示', '确定离开', '继续修改', '您的信息尚未保存', + leftTap: () { popPage(); - },rightTap: (){ + popPage(); + }, rightTap: () { popPage(); }); } else { @@ -76,75 +78,83 @@ class ModifyUserInformationPage extends StatelessWidget { ), body: SingleChildScrollView( child: Column( - children: [ - Padding( - padding: EdgeInsets.only(left: 65.w, right: 55.w, top: 38.h), - child: Row( - children: [ - Text( - type.title, - style: TextStyle( - fontWeight: FontWeight.w700, - color: const Color(0xFF333333), - fontSize: 21.sp, - ), - ), - 20.horizontalSpace, - // 输入框 or 选择框 - _buildTextFieldWidget(context), - // 占位 - Expanded( - child: Container(), - ), - // 按钮 - GestureDetector( - onTap: () { - var text = ''; - if (type == ModifyUserInformationType.name || type == ModifyUserInformationType.age){ - if(bloc.modifyTextController.text.isEmpty) { - showToast('内容不能为空'); - return; - } - text = bloc.modifyTextController.text; - } - - if (type == ModifyUserInformationType.gender) { - text = bloc.gender.toString(); - } - // 更新type类型的字段 - context.read().add(UserUpdate(type,text)); - }, - child: Container( - alignment: Alignment.center, - width: 90.w, - height: 44.h, - decoration: const BoxDecoration( - image: DecorationImage(image: AssetImage(AssetsConst.bgButtonBlue), fit: BoxFit.fill), - ), - child: Text( - '确定', - style: TextStyle(fontSize: 17.sp, color: Colors.white), - ), - ), - ) - ], - )), - Stack( - alignment: Alignment.topRight, + children: [ + Padding( + padding: + EdgeInsets.only(left: 65.w, right: 55.w, top: 38.h), + child: Row( children: [ - Image.asset( - AssetsConst.bgEditUserInformation, - width: double.infinity, + Text( + type.title, + style: TextStyle( + fontWeight: FontWeight.w700, + color: const Color(0xFF333333), + fontSize: 21.sp, + ), ), - Positioned( - right: 125.w, - top: 10.h, - child: Image.asset(AssetsConst.bgIcSteveWrite, width: 161.w, height: 249.w), + 20.horizontalSpace, + // 输入框 or 选择框 + _buildTextFieldWidget(context), + // 占位 + Expanded( + child: Container(), ), + // 按钮 + GestureDetector( + onTap: () { + var text = ''; + if (type == ModifyUserInformationType.name || + type == ModifyUserInformationType.age) { + if (bloc.modifyTextController.text.isEmpty) { + showToast('内容不能为空'); + return; + } + text = bloc.modifyTextController.text; + } + + if (type == ModifyUserInformationType.gender) { + text = bloc.gender.toString(); + } + // 更新type类型的字段 + context + .read() + .add(UserUpdate(type, text)); + }, + child: Container( + alignment: Alignment.center, + width: 90.w, + height: 44.h, + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage(AssetsConst.bgButtonBlue), + fit: BoxFit.fill), + ), + child: Text( + '确定', + style: TextStyle( + fontSize: 17.sp, color: Colors.white), + ), + ), + ) ], + )), + Stack( + alignment: Alignment.topRight, + children: [ + Image.asset( + AssetsConst.bgEditUserInformation, + width: double.infinity, + ), + Positioned( + right: 125.w, + top: 10.h, + child: Image.asset(AssetsConst.bgIcSteveWrite, + width: 161.w, height: 249.w), ), ], - )), + ), + ], + )), ); }, ), @@ -155,22 +165,22 @@ class ModifyUserInformationPage extends StatelessWidget { Widget _buildTextFieldWidget(BuildContext context) { if (type == ModifyUserInformationType.gender) { return BlocBuilder( - builder: (context,state){ - final bloc = BlocProvider.of(context); - return Row( - children: [ - GestureDetector( - onTap: () => bloc.add(ChangeGenderEvent(0)), - child: _buildSexWidget('男', bloc.gender == 0), - ), - 70.horizontalSpace, - GestureDetector( - onTap: () => bloc.add(ChangeGenderEvent(1)), - child: _buildSexWidget('女', bloc.gender == 1), - ) - ], - ); - }); + builder: (context, state) { + final bloc = BlocProvider.of(context); + return Row( + children: [ + GestureDetector( + onTap: () => bloc.add(ChangeGenderEvent(0)), + child: _buildSexWidget('男', bloc.gender == 0), + ), + 70.horizontalSpace, + GestureDetector( + onTap: () => bloc.add(ChangeGenderEvent(1)), + child: _buildSexWidget('女', bloc.gender == 1), + ) + ], + ); + }); } var formatters = [ @@ -187,29 +197,28 @@ class ModifyUserInformationPage extends StatelessWidget { inputType = TextInputType.number; } - return BlocBuilder( - builder: (context,state){ - final bloc = BlocProvider.of(context); - return TextFieldCustomerWidget( - height: 65.h, - width: 222.w, - textStyle: TextStyle( - fontWeight: FontWeight.w700, - color: const Color(0xFF333333), - fontSize: 21.sp, - ), - bgImageName: 'Input_layer_up', - textInputType: inputType, - inputFormatters: formatters, - controller: bloc.modifyTextController, - onChangeValue: (String value) { - bloc.add(ChangeTextFieldEvent(value)); - }, - ); - }); + return BlocBuilder(builder: (context, state) { + final bloc = BlocProvider.of(context); + return TextFieldCustomerWidget( + height: 65.h, + width: 222.w, + textStyle: TextStyle( + fontWeight: FontWeight.w700, + color: const Color(0xFF333333), + fontSize: 21.sp, + ), + bgImageName: 'Input_layer_up', + textInputType: inputType, + inputFormatters: formatters, + controller: bloc.modifyTextController, + onChangeValue: (String value) { + bloc.add(ChangeTextFieldEvent(value)); + }, + ); + }); } - Widget _buildSexWidget(String title,bool isSelect) { + Widget _buildSexWidget(String title, bool isSelect) { return Row( children: [ Container( @@ -218,13 +227,9 @@ class ModifyUserInformationPage extends StatelessWidget { padding: EdgeInsets.all(4.h), decoration: BoxDecoration( borderRadius: BorderRadius.circular(21.r), - border: Border.all( - color: const Color(0xFF140C10), - width: 1.5 - ) - ), + border: Border.all(color: const Color(0xFF140C10), width: 1.5)), child: Offstage( - offstage:!isSelect, + offstage: !isSelect, child: ClipRRect( borderRadius: BorderRadius.circular(13.r), child: Container( diff --git a/lib/pages/user/modify/user_info_bloc/user_info_bloc.dart b/lib/pages/user/modify/user_info_bloc/user_info_bloc.dart index e834f91..3d9cb9e 100644 --- a/lib/pages/user/modify/user_info_bloc/user_info_bloc.dart +++ b/lib/pages/user/modify/user_info_bloc/user_info_bloc.dart @@ -8,7 +8,7 @@ part 'user_info_state.dart'; class UserInfoBloc extends Bloc { final TextEditingController modifyTextController = TextEditingController(); - int _gender = UserUtil.getUser()!.gender??0; + int _gender = UserUtil.getUser()!.gender ?? 0; int get gender => _gender; @@ -22,18 +22,25 @@ class UserInfoBloc extends Bloc { on(_initControllerText); } - void _initControllerText(InitControllerTextEvent event,Emitter emitter) async { - modifyTextController.text = event.text; + void _initControllerText( + InitControllerTextEvent event, Emitter emitter) async { + if (event.text == 'null') { + modifyTextController.text = '0'; + } else { + modifyTextController.text = event.text; + } _primitiveText = event.text; } - void _changeGender(ChangeGenderEvent event,Emitter emitter) async { + void _changeGender( + ChangeGenderEvent event, Emitter emitter) async { _gender = event.gender; - isChangeInfo = _gender != (UserUtil.getUser()!.gender??0); + isChangeInfo = _gender != (UserUtil.getUser()!.gender ?? 0); emitter(ChangeGenderState()); } - void _changeTextField(ChangeTextFieldEvent event,Emitter emitter) async { + void _changeTextField( + ChangeTextFieldEvent event, Emitter emitter) async { isChangeInfo = _primitiveText != event.text; } }