Commit 80aafd80eefadd50c0c922868ef8405b060811fb

Authored by biao
1 parent ecfd79f5

修复 新用户修改年龄页面显示null;编辑年龄之后 点击确认离开无效

lib/pages/user/information/user_information_page.dart
@@ -17,16 +17,13 @@ class UserInformationPage extends StatelessWidget { @@ -17,16 +17,13 @@ class UserInformationPage extends StatelessWidget {
17 17
18 @override 18 @override
19 Widget build(BuildContext context) { 19 Widget build(BuildContext context) {
20 - return BlocBuilder<UserBloc, UserState>(  
21 - builder: (context,state){  
22 - return _UserInformationContentView();  
23 - }); 20 + return BlocBuilder<UserBloc, UserState>(builder: (context, state) {
  21 + return _UserInformationContentView();
  22 + });
24 } 23 }
25 } 24 }
26 25
27 -  
28 class _UserInformationContentView extends StatelessWidget { 26 class _UserInformationContentView extends StatelessWidget {
29 -  
30 void _openModifyPage(BuildContext context, ModifyUserInformationType type) { 27 void _openModifyPage(BuildContext context, ModifyUserInformationType type) {
31 Log.d('_openModifyPage($type)'); 28 Log.d('_openModifyPage($type)');
32 ModifyUserInformationPage.push(context, type); 29 ModifyUserInformationPage.push(context, type);
@@ -41,7 +38,8 @@ class _UserInformationContentView extends StatelessWidget { @@ -41,7 +38,8 @@ class _UserInformationContentView extends StatelessWidget {
41 titleText: "个人信息", 38 titleText: "个人信息",
42 ), 39 ),
43 body: SingleChildScrollView( 40 body: SingleChildScrollView(
44 - padding: EdgeInsets.only(left: 17.w, right: 17.w, top: 10.h, bottom: 22.h), 41 + padding:
  42 + EdgeInsets.only(left: 17.w, right: 17.w, top: 10.h, bottom: 22.h),
45 child: Column( 43 child: Column(
46 children: [ 44 children: [
47 _buildContentRow( 45 _buildContentRow(
@@ -51,11 +49,12 @@ class _UserInformationContentView extends StatelessWidget { @@ -51,11 +49,12 @@ class _UserInformationContentView extends StatelessWidget {
51 backgroundColor: const Color(0xFF140C10), 49 backgroundColor: const Color(0xFF140C10),
52 child: CircleAvatar( 50 child: CircleAvatar(
53 radius: 21.r, 51 radius: 21.r,
54 - backgroundImage: ImageUtil.getImageProviderOnDefault(user.avatarUrl), 52 + backgroundImage:
  53 + ImageUtil.getImageProviderOnDefault(user.avatarUrl),
55 ), 54 ),
56 ), 55 ),
57 - onTap: () => pushNamed(AppRouteName.userAvatar,arguments: {'pageType':'1'})  
58 - ), 56 + onTap: () => pushNamed(AppRouteName.userAvatar,
  57 + arguments: {'pageType': '1'})),
59 11.verticalSpace, 58 11.verticalSpace,
60 _buildContentRow( 59 _buildContentRow(
61 '名字', 60 '名字',
@@ -67,19 +66,21 @@ class _UserInformationContentView extends StatelessWidget { @@ -67,19 +66,21 @@ class _UserInformationContentView extends StatelessWidget {
67 fontSize: 21.sp, 66 fontSize: 21.sp,
68 ), 67 ),
69 ), 68 ),
70 - onTap: () => _openModifyPage(context, ModifyUserInformationType.name)), 69 + onTap: () =>
  70 + _openModifyPage(context, ModifyUserInformationType.name)),
71 11.verticalSpace, 71 11.verticalSpace,
72 _buildContentRow( 72 _buildContentRow(
73 '年龄', 73 '年龄',
74 Text( 74 Text(
75 - (user.age??0).toString(), 75 + (user.age ?? 0).toString(),
76 style: TextStyle( 76 style: TextStyle(
77 fontWeight: FontWeight.w500, 77 fontWeight: FontWeight.w500,
78 color: const Color(0xFF333333), 78 color: const Color(0xFF333333),
79 fontSize: 21.sp, 79 fontSize: 21.sp,
80 ), 80 ),
81 ), 81 ),
82 - onTap: () => _openModifyPage(context, ModifyUserInformationType.age)), 82 + onTap: () =>
  83 + _openModifyPage(context, ModifyUserInformationType.age)),
83 11.verticalSpace, 84 11.verticalSpace,
84 _buildContentRow( 85 _buildContentRow(
85 '性别', 86 '性别',
@@ -91,7 +92,8 @@ class _UserInformationContentView extends StatelessWidget { @@ -91,7 +92,8 @@ class _UserInformationContentView extends StatelessWidget {
91 fontSize: 21.sp, 92 fontSize: 21.sp,
92 ), 93 ),
93 ), 94 ),
94 - onTap: () => _openModifyPage(context, ModifyUserInformationType.gender)), 95 + onTap: () =>
  96 + _openModifyPage(context, ModifyUserInformationType.gender)),
95 11.verticalSpace, 97 11.verticalSpace,
96 _buildContentRow( 98 _buildContentRow(
97 '账号', 99 '账号',
@@ -111,14 +113,18 @@ class _UserInformationContentView extends StatelessWidget { @@ -111,14 +113,18 @@ class _UserInformationContentView extends StatelessWidget {
111 ); 113 );
112 } 114 }
113 115
114 - Widget _buildContentRow(String filedName, Widget contentWidget, {bool isHideEndIcon = false, Function()? onTap}) { 116 + Widget _buildContentRow(String filedName, Widget contentWidget,
  117 + {bool isHideEndIcon = false, Function()? onTap}) {
115 return GestureDetector( 118 return GestureDetector(
116 onTap: onTap, 119 onTap: onTap,
117 child: Container( 120 child: Container(
118 - padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 18.h, bottom: 18.h), 121 + padding:
  122 + EdgeInsets.only(left: 16.w, right: 16.w, top: 18.h, bottom: 18.h),
119 decoration: BoxDecoration( 123 decoration: BoxDecoration(
120 image: DecorationImage( 124 image: DecorationImage(
121 - image: ImageUtil.getImageProviderOnDefault(AssetsConst.bgUserInformationText), fit: BoxFit.fill)), 125 + image: ImageUtil.getImageProviderOnDefault(
  126 + AssetsConst.bgUserInformationText),
  127 + fit: BoxFit.fill)),
122 child: Row(children: [ 128 child: Row(children: [
123 Text( 129 Text(
124 filedName, 130 filedName,
@@ -131,9 +137,9 @@ class _UserInformationContentView extends StatelessWidget { @@ -131,9 +137,9 @@ class _UserInformationContentView extends StatelessWidget {
131 32.horizontalSpace, 137 32.horizontalSpace,
132 Expanded( 138 Expanded(
133 child: Container( 139 child: Container(
134 - alignment: Alignment.centerLeft,  
135 - child: contentWidget,  
136 - )), 140 + alignment: Alignment.centerLeft,
  141 + child: contentWidget,
  142 + )),
137 Offstage( 143 Offstage(
138 offstage: isHideEndIcon, 144 offstage: isHideEndIcon,
139 child: Image.asset(AssetsConst.icNext, width: 20.w, height: 25.h), 145 child: Image.asset(AssetsConst.icNext, width: 20.w, height: 25.h),
lib/pages/user/modify/modify_user_information_page.dart
@@ -47,7 +47,7 @@ class ModifyUserInformationPage extends StatelessWidget { @@ -47,7 +47,7 @@ class ModifyUserInformationPage extends StatelessWidget {
47 create: (context) => UserInfoBloc()..add(InitControllerTextEvent(text)), 47 create: (context) => UserInfoBloc()..add(InitControllerTextEvent(text)),
48 child: MultiBlocListener( 48 child: MultiBlocListener(
49 listeners: [ 49 listeners: [
50 - BlocListener<UserBloc,UserState>(listener: (context, state){ 50 + BlocListener<UserBloc, UserState>(listener: (context, state) {
51 if (state is UserInfoUpdated) { 51 if (state is UserInfoUpdated) {
52 showToast('修改成功'); 52 showToast('修改成功');
53 popPage(); 53 popPage();
@@ -64,9 +64,11 @@ class ModifyUserInformationPage extends StatelessWidget { @@ -64,9 +64,11 @@ class ModifyUserInformationPage extends StatelessWidget {
64 onBack: () { 64 onBack: () {
65 final bloc = BlocProvider.of<UserInfoBloc>(context); 65 final bloc = BlocProvider.of<UserInfoBloc>(context);
66 if (bloc.isChangeInfo) { 66 if (bloc.isChangeInfo) {
67 - showTwoActionDialog('提示', '确定离开', '继续修改', '您的信息尚未保存',leftTap: (){ 67 + showTwoActionDialog('提示', '确定离开', '继续修改', '您的信息尚未保存',
  68 + leftTap: () {
68 popPage(); 69 popPage();
69 - },rightTap: (){ 70 + popPage();
  71 + }, rightTap: () {
70 popPage(); 72 popPage();
71 }); 73 });
72 } else { 74 } else {
@@ -76,75 +78,83 @@ class ModifyUserInformationPage extends StatelessWidget { @@ -76,75 +78,83 @@ class ModifyUserInformationPage extends StatelessWidget {
76 ), 78 ),
77 body: SingleChildScrollView( 79 body: SingleChildScrollView(
78 child: Column( 80 child: Column(
79 - children: [  
80 - Padding(  
81 - padding: EdgeInsets.only(left: 65.w, right: 55.w, top: 38.h),  
82 - child: Row(  
83 - children: [  
84 - Text(  
85 - type.title,  
86 - style: TextStyle(  
87 - fontWeight: FontWeight.w700,  
88 - color: const Color(0xFF333333),  
89 - fontSize: 21.sp,  
90 - ),  
91 - ),  
92 - 20.horizontalSpace,  
93 - // 输入框 or 选择框  
94 - _buildTextFieldWidget(context),  
95 - // 占位  
96 - Expanded(  
97 - child: Container(),  
98 - ),  
99 - // 按钮  
100 - GestureDetector(  
101 - onTap: () {  
102 - var text = '';  
103 - if (type == ModifyUserInformationType.name || type == ModifyUserInformationType.age){  
104 - if(bloc.modifyTextController.text.isEmpty) {  
105 - showToast('内容不能为空');  
106 - return;  
107 - }  
108 - text = bloc.modifyTextController.text;  
109 - }  
110 -  
111 - if (type == ModifyUserInformationType.gender) {  
112 - text = bloc.gender.toString();  
113 - }  
114 - // 更新type类型的字段  
115 - context.read<UserBloc>().add(UserUpdate(type,text));  
116 - },  
117 - child: Container(  
118 - alignment: Alignment.center,  
119 - width: 90.w,  
120 - height: 44.h,  
121 - decoration: const BoxDecoration(  
122 - image: DecorationImage(image: AssetImage(AssetsConst.bgButtonBlue), fit: BoxFit.fill),  
123 - ),  
124 - child: Text(  
125 - '确定',  
126 - style: TextStyle(fontSize: 17.sp, color: Colors.white),  
127 - ),  
128 - ),  
129 - )  
130 - ],  
131 - )),  
132 - Stack(  
133 - alignment: Alignment.topRight, 81 + children: [
  82 + Padding(
  83 + padding:
  84 + EdgeInsets.only(left: 65.w, right: 55.w, top: 38.h),
  85 + child: Row(
134 children: [ 86 children: [
135 - Image.asset(  
136 - AssetsConst.bgEditUserInformation,  
137 - width: double.infinity, 87 + Text(
  88 + type.title,
  89 + style: TextStyle(
  90 + fontWeight: FontWeight.w700,
  91 + color: const Color(0xFF333333),
  92 + fontSize: 21.sp,
  93 + ),
138 ), 94 ),
139 - Positioned(  
140 - right: 125.w,  
141 - top: 10.h,  
142 - child: Image.asset(AssetsConst.bgIcSteveWrite, width: 161.w, height: 249.w), 95 + 20.horizontalSpace,
  96 + // 输入框 or 选择框
  97 + _buildTextFieldWidget(context),
  98 + // 占位
  99 + Expanded(
  100 + child: Container(),
143 ), 101 ),
  102 + // 按钮
  103 + GestureDetector(
  104 + onTap: () {
  105 + var text = '';
  106 + if (type == ModifyUserInformationType.name ||
  107 + type == ModifyUserInformationType.age) {
  108 + if (bloc.modifyTextController.text.isEmpty) {
  109 + showToast('内容不能为空');
  110 + return;
  111 + }
  112 + text = bloc.modifyTextController.text;
  113 + }
  114 +
  115 + if (type == ModifyUserInformationType.gender) {
  116 + text = bloc.gender.toString();
  117 + }
  118 + // 更新type类型的字段
  119 + context
  120 + .read<UserBloc>()
  121 + .add(UserUpdate(type, text));
  122 + },
  123 + child: Container(
  124 + alignment: Alignment.center,
  125 + width: 90.w,
  126 + height: 44.h,
  127 + decoration: const BoxDecoration(
  128 + image: DecorationImage(
  129 + image: AssetImage(AssetsConst.bgButtonBlue),
  130 + fit: BoxFit.fill),
  131 + ),
  132 + child: Text(
  133 + '确定',
  134 + style: TextStyle(
  135 + fontSize: 17.sp, color: Colors.white),
  136 + ),
  137 + ),
  138 + )
144 ], 139 ],
  140 + )),
  141 + Stack(
  142 + alignment: Alignment.topRight,
  143 + children: [
  144 + Image.asset(
  145 + AssetsConst.bgEditUserInformation,
  146 + width: double.infinity,
  147 + ),
  148 + Positioned(
  149 + right: 125.w,
  150 + top: 10.h,
  151 + child: Image.asset(AssetsConst.bgIcSteveWrite,
  152 + width: 161.w, height: 249.w),
145 ), 153 ),
146 ], 154 ],
147 - )), 155 + ),
  156 + ],
  157 + )),
148 ); 158 );
149 }, 159 },
150 ), 160 ),
@@ -155,22 +165,22 @@ class ModifyUserInformationPage extends StatelessWidget { @@ -155,22 +165,22 @@ class ModifyUserInformationPage extends StatelessWidget {
155 Widget _buildTextFieldWidget(BuildContext context) { 165 Widget _buildTextFieldWidget(BuildContext context) {
156 if (type == ModifyUserInformationType.gender) { 166 if (type == ModifyUserInformationType.gender) {
157 return BlocBuilder<UserInfoBloc, UserInfoState>( 167 return BlocBuilder<UserInfoBloc, UserInfoState>(
158 - builder: (context,state){  
159 - final bloc = BlocProvider.of<UserInfoBloc>(context);  
160 - return Row(  
161 - children: <Widget>[  
162 - GestureDetector(  
163 - onTap: () => bloc.add(ChangeGenderEvent(0)),  
164 - child: _buildSexWidget('男', bloc.gender == 0),  
165 - ),  
166 - 70.horizontalSpace,  
167 - GestureDetector(  
168 - onTap: () => bloc.add(ChangeGenderEvent(1)),  
169 - child: _buildSexWidget('女', bloc.gender == 1),  
170 - )  
171 - ],  
172 - );  
173 - }); 168 + builder: (context, state) {
  169 + final bloc = BlocProvider.of<UserInfoBloc>(context);
  170 + return Row(
  171 + children: <Widget>[
  172 + GestureDetector(
  173 + onTap: () => bloc.add(ChangeGenderEvent(0)),
  174 + child: _buildSexWidget('男', bloc.gender == 0),
  175 + ),
  176 + 70.horizontalSpace,
  177 + GestureDetector(
  178 + onTap: () => bloc.add(ChangeGenderEvent(1)),
  179 + child: _buildSexWidget('女', bloc.gender == 1),
  180 + )
  181 + ],
  182 + );
  183 + });
174 } 184 }
175 185
176 var formatters = [ 186 var formatters = [
@@ -187,29 +197,28 @@ class ModifyUserInformationPage extends StatelessWidget { @@ -187,29 +197,28 @@ class ModifyUserInformationPage extends StatelessWidget {
187 inputType = TextInputType.number; 197 inputType = TextInputType.number;
188 } 198 }
189 199
190 - return BlocBuilder<UserInfoBloc, UserInfoState>(  
191 - builder: (context,state){  
192 - final bloc = BlocProvider.of<UserInfoBloc>(context);  
193 - return TextFieldCustomerWidget(  
194 - height: 65.h,  
195 - width: 222.w,  
196 - textStyle: TextStyle(  
197 - fontWeight: FontWeight.w700,  
198 - color: const Color(0xFF333333),  
199 - fontSize: 21.sp,  
200 - ),  
201 - bgImageName: 'Input_layer_up',  
202 - textInputType: inputType,  
203 - inputFormatters: formatters,  
204 - controller: bloc.modifyTextController,  
205 - onChangeValue: (String value) {  
206 - bloc.add(ChangeTextFieldEvent(value));  
207 - },  
208 - );  
209 - }); 200 + return BlocBuilder<UserInfoBloc, UserInfoState>(builder: (context, state) {
  201 + final bloc = BlocProvider.of<UserInfoBloc>(context);
  202 + return TextFieldCustomerWidget(
  203 + height: 65.h,
  204 + width: 222.w,
  205 + textStyle: TextStyle(
  206 + fontWeight: FontWeight.w700,
  207 + color: const Color(0xFF333333),
  208 + fontSize: 21.sp,
  209 + ),
  210 + bgImageName: 'Input_layer_up',
  211 + textInputType: inputType,
  212 + inputFormatters: formatters,
  213 + controller: bloc.modifyTextController,
  214 + onChangeValue: (String value) {
  215 + bloc.add(ChangeTextFieldEvent(value));
  216 + },
  217 + );
  218 + });
210 } 219 }
211 220
212 - Widget _buildSexWidget(String title,bool isSelect) { 221 + Widget _buildSexWidget(String title, bool isSelect) {
213 return Row( 222 return Row(
214 children: [ 223 children: [
215 Container( 224 Container(
@@ -218,13 +227,9 @@ class ModifyUserInformationPage extends StatelessWidget { @@ -218,13 +227,9 @@ class ModifyUserInformationPage extends StatelessWidget {
218 padding: EdgeInsets.all(4.h), 227 padding: EdgeInsets.all(4.h),
219 decoration: BoxDecoration( 228 decoration: BoxDecoration(
220 borderRadius: BorderRadius.circular(21.r), 229 borderRadius: BorderRadius.circular(21.r),
221 - border: Border.all(  
222 - color: const Color(0xFF140C10),  
223 - width: 1.5  
224 - )  
225 - ), 230 + border: Border.all(color: const Color(0xFF140C10), width: 1.5)),
226 child: Offstage( 231 child: Offstage(
227 - offstage:!isSelect, 232 + offstage: !isSelect,
228 child: ClipRRect( 233 child: ClipRRect(
229 borderRadius: BorderRadius.circular(13.r), 234 borderRadius: BorderRadius.circular(13.r),
230 child: Container( 235 child: Container(
lib/pages/user/modify/user_info_bloc/user_info_bloc.dart
@@ -8,7 +8,7 @@ part &#39;user_info_state.dart&#39;; @@ -8,7 +8,7 @@ part &#39;user_info_state.dart&#39;;
8 class UserInfoBloc extends Bloc<UserInfoEvent, UserInfoState> { 8 class UserInfoBloc extends Bloc<UserInfoEvent, UserInfoState> {
9 final TextEditingController modifyTextController = TextEditingController(); 9 final TextEditingController modifyTextController = TextEditingController();
10 10
11 - int _gender = UserUtil.getUser()!.gender??0; 11 + int _gender = UserUtil.getUser()!.gender ?? 0;
12 12
13 int get gender => _gender; 13 int get gender => _gender;
14 14
@@ -22,18 +22,25 @@ class UserInfoBloc extends Bloc&lt;UserInfoEvent, UserInfoState&gt; { @@ -22,18 +22,25 @@ class UserInfoBloc extends Bloc&lt;UserInfoEvent, UserInfoState&gt; {
22 on<InitControllerTextEvent>(_initControllerText); 22 on<InitControllerTextEvent>(_initControllerText);
23 } 23 }
24 24
25 - void _initControllerText(InitControllerTextEvent event,Emitter<UserInfoState> emitter) async {  
26 - modifyTextController.text = event.text; 25 + void _initControllerText(
  26 + InitControllerTextEvent event, Emitter<UserInfoState> emitter) async {
  27 + if (event.text == 'null') {
  28 + modifyTextController.text = '0';
  29 + } else {
  30 + modifyTextController.text = event.text;
  31 + }
27 _primitiveText = event.text; 32 _primitiveText = event.text;
28 } 33 }
29 34
30 - void _changeGender(ChangeGenderEvent event,Emitter<UserInfoState> emitter) async { 35 + void _changeGender(
  36 + ChangeGenderEvent event, Emitter<UserInfoState> emitter) async {
31 _gender = event.gender; 37 _gender = event.gender;
32 - isChangeInfo = _gender != (UserUtil.getUser()!.gender??0); 38 + isChangeInfo = _gender != (UserUtil.getUser()!.gender ?? 0);
33 emitter(ChangeGenderState()); 39 emitter(ChangeGenderState());
34 } 40 }
35 41
36 - void _changeTextField(ChangeTextFieldEvent event,Emitter<UserInfoState> emitter) async { 42 + void _changeTextField(
  43 + ChangeTextFieldEvent event, Emitter<UserInfoState> emitter) async {
37 isChangeInfo = _primitiveText != event.text; 44 isChangeInfo = _primitiveText != event.text;
38 } 45 }
39 } 46 }