Commit e1f365548c0ee1cb18b58e9ac8f77823de86493b
1 parent
17a80689
feat:调整状态监听逻辑
Showing
11 changed files
with
249 additions
and
203 deletions
lib/login/forgetpwd/bloc/forget_pwd_home_bloc.dart
1 | 1 | import 'package:flutter/cupertino.dart'; |
2 | 2 | import 'package:flutter_bloc/flutter_bloc.dart'; |
3 | +import 'package:common_utils/common_utils.dart'; | |
4 | +import 'package:flutter_easyloading/flutter_easyloading.dart'; | |
3 | 5 | |
4 | 6 | part 'forget_pwd_home_event.dart'; |
5 | 7 | part 'forget_pwd_home_state.dart'; |
... | ... | @@ -56,7 +58,11 @@ class ForgetPwdHomeBloc extends Bloc<ForgetPwdHomeEvent, ForgetPwdHomeState> { |
56 | 58 | } |
57 | 59 | |
58 | 60 | void _setPassWord(SetPassWordEvent event,Emitter<ForgetPwdHomeState> emitter) async { |
59 | - | |
61 | + if(!RegexUtil.isMobileExact(phoneNumController.text)) { | |
62 | + EasyLoading.showToast('手机号不正确!'); | |
63 | + return; | |
64 | + } | |
65 | + emitter(SetPwdCheckCodeState()); | |
60 | 66 | } |
61 | 67 | |
62 | 68 | void _sendSmsCode(SendSmsCodeEvent event,Emitter<ForgetPwdHomeState> emitter) async { | ... | ... |
lib/login/forgetpwd/bloc/forget_pwd_home_state.dart
... | ... | @@ -4,7 +4,9 @@ part of 'forget_pwd_home_bloc.dart'; |
4 | 4 | abstract class ForgetPwdHomeState {} |
5 | 5 | |
6 | 6 | class ForgetPwdHomeInitial extends ForgetPwdHomeState {} |
7 | - | |
7 | +///是否能发送验证码 | |
8 | 8 | class SendSmsCodeTypeChangeState extends ForgetPwdHomeState {} |
9 | - | |
9 | +///是否能设置密码 | |
10 | 10 | class SetPwdTypeChangeState extends ForgetPwdHomeState {} |
11 | +///验证码验证是否成功 | |
12 | +class SetPwdCheckCodeState extends ForgetPwdHomeState {} | ... | ... |
lib/login/forgetpwd/forget_password_home_page.dart
... | ... | @@ -4,6 +4,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; |
4 | 4 | import 'package:wow_english/common/extension/string_extension.dart'; |
5 | 5 | import 'package:wow_english/common/widgets/textfield_customer_widget.dart'; |
6 | 6 | import 'package:wow_english/login/forgetpwd/bloc/forget_pwd_home_bloc.dart'; |
7 | +import 'package:wow_english/route/route.dart'; | |
7 | 8 | |
8 | 9 | class ForgetPasswordHomePage extends StatelessWidget { |
9 | 10 | const ForgetPasswordHomePage({super.key}); |
... | ... | @@ -12,165 +13,179 @@ class ForgetPasswordHomePage extends StatelessWidget { |
12 | 13 | Widget build(BuildContext context) { |
13 | 14 | return BlocProvider( |
14 | 15 | create: (context) => ForgetPwdHomeBloc(), |
16 | + child: _ForgetPasswordHomePageView(), | |
17 | + ); | |
18 | + } | |
19 | +} | |
20 | + | |
21 | +class _ForgetPasswordHomePageView extends StatelessWidget { | |
22 | + @override | |
23 | + Widget build(BuildContext context) { | |
24 | + return BlocListener<ForgetPwdHomeBloc, ForgetPwdHomeState>( | |
25 | + listener: (context, state) { | |
26 | + if (state is SetPwdCheckCodeState) { | |
27 | + Navigator.of(context).pushNamed(AppRouteName.setPwd,arguments: {'phoneNumber':context.read<ForgetPwdHomeBloc>().phoneNumController.text}); | |
28 | + } | |
29 | + }, | |
15 | 30 | child: _buildForgetPwdView(), |
16 | 31 | ); |
17 | 32 | } |
18 | 33 | |
19 | 34 | Widget _buildForgetPwdView() => BlocBuilder<ForgetPwdHomeBloc, ForgetPwdHomeState>( |
20 | - builder: (context, state) { | |
21 | - final bloc = BlocProvider.of<ForgetPwdHomeBloc>(context); | |
22 | - return Scaffold( | |
23 | - body: Container( | |
24 | - color: Colors.white, | |
25 | - child: SafeArea( | |
26 | - child: ListView( | |
27 | - children: [ | |
28 | - Padding( | |
29 | - padding: EdgeInsets.only(left: 49.w,right: 10.w), | |
30 | - child: Column( | |
31 | - children: [ | |
32 | - 34.verticalSpace, | |
33 | - Row( | |
34 | - children: [ | |
35 | - Image.asset( | |
36 | - 'wow_logo'.assetPng, | |
37 | - height: 49.w, | |
38 | - width: 83.5.h, | |
39 | - ), | |
40 | - 12.5.horizontalSpace, | |
41 | - const Text( | |
42 | - '修改密码\n请输入您的手机号和验证码吧', | |
43 | - style: TextStyle( | |
44 | - fontSize: 16.5, | |
45 | - color: Color(0xFF666666) | |
35 | + builder: (context, state) { | |
36 | + final bloc = BlocProvider.of<ForgetPwdHomeBloc>(context); | |
37 | + return Scaffold( | |
38 | + body: Container( | |
39 | + color: Colors.white, | |
40 | + child: SafeArea( | |
41 | + child: ListView( | |
42 | + children: [ | |
43 | + Padding( | |
44 | + padding: EdgeInsets.only(left: 49.w,right: 10.w), | |
45 | + child: Column( | |
46 | + children: [ | |
47 | + 34.verticalSpace, | |
48 | + Row( | |
49 | + children: [ | |
50 | + Image.asset( | |
51 | + 'wow_logo'.assetPng, | |
52 | + height: 49.w, | |
53 | + width: 83.5.h, | |
46 | 54 | ), |
47 | - ) | |
48 | - ], | |
49 | - ), | |
50 | - Row( | |
51 | - crossAxisAlignment: CrossAxisAlignment.start, | |
52 | - children: [ | |
53 | - Expanded( | |
54 | - child: Column( | |
55 | - children: [ | |
56 | - 44.5.verticalSpace, | |
57 | - Row( | |
58 | - children: [ | |
59 | - Image.asset( | |
60 | - 'phone'.assetPng, | |
61 | - height: 45.h, | |
62 | - width: 35.w, | |
63 | - ), | |
64 | - 15.horizontalSpace, | |
65 | - Expanded( | |
66 | - child: TextFieldCustomerWidget( | |
67 | - height: 50.h, | |
68 | - hitText: '请输入当前手机号', | |
69 | - textInputType: TextInputType.phone, | |
70 | - bgImageName: 'Input_layer_up', | |
71 | - onChangeValue: (String value) { | |
72 | - bloc.add(PhoneNumChangeEvent()); | |
73 | - }, | |
74 | - controller: bloc.phoneNumController, | |
75 | - ) | |
76 | - ) | |
77 | - ], | |
78 | - ), | |
79 | - 11.5.verticalSpace, | |
80 | - Row( | |
81 | - mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
82 | - children: [ | |
83 | - Image.asset( | |
84 | - 'lock'.assetPng, | |
85 | - height: 34.h, | |
86 | - width: 31.w, | |
87 | - ), | |
88 | - 18.5.horizontalSpace, | |
89 | - Expanded( | |
90 | - child: TextFieldCustomerWidget( | |
91 | - hitText: '请输入验证码', | |
92 | - bgImageName: 'Input_layer_down', | |
93 | - onChangeValue: (String value) { | |
94 | - bloc.add(CheckCodeChangeEvent()); | |
95 | - }, | |
96 | - textInputType: TextInputType.emailAddress, | |
97 | - controller: bloc.checkNumController, | |
98 | - ) | |
99 | - ), | |
100 | - 16.5.horizontalSpace, | |
101 | - GestureDetector( | |
102 | - onTap: () { | |
103 | - if (bloc.canSendSms) { | |
104 | - bloc.add(SendSmsCodeEvent()); | |
105 | - } | |
106 | - }, | |
107 | - child: Container( | |
108 | - decoration: BoxDecoration( | |
109 | - image: DecorationImage( | |
110 | - image: AssetImage( | |
111 | - bloc.canSendSms?'securitycode'.assetPng:'securitycode_dis'.assetPng | |
112 | - ), | |
113 | - fit: BoxFit.fill | |
55 | + 12.5.horizontalSpace, | |
56 | + const Text( | |
57 | + '修改密码\n请输入您的手机号和验证码吧', | |
58 | + style: TextStyle( | |
59 | + fontSize: 16.5, | |
60 | + color: Color(0xFF666666) | |
61 | + ), | |
62 | + ) | |
63 | + ], | |
64 | + ), | |
65 | + Row( | |
66 | + crossAxisAlignment: CrossAxisAlignment.start, | |
67 | + children: [ | |
68 | + Expanded( | |
69 | + child: Column( | |
70 | + children: [ | |
71 | + 44.5.verticalSpace, | |
72 | + Row( | |
73 | + children: [ | |
74 | + Image.asset( | |
75 | + 'phone'.assetPng, | |
76 | + height: 45.h, | |
77 | + width: 35.w, | |
78 | + ), | |
79 | + 15.horizontalSpace, | |
80 | + Expanded( | |
81 | + child: TextFieldCustomerWidget( | |
82 | + height: 50.h, | |
83 | + hitText: '请输入当前手机号', | |
84 | + textInputType: TextInputType.phone, | |
85 | + bgImageName: 'Input_layer_up', | |
86 | + onChangeValue: (String value) { | |
87 | + bloc.add(PhoneNumChangeEvent()); | |
88 | + }, | |
89 | + controller: bloc.phoneNumController, | |
90 | + ) | |
91 | + ) | |
92 | + ], | |
93 | + ), | |
94 | + 11.5.verticalSpace, | |
95 | + Row( | |
96 | + mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
97 | + children: [ | |
98 | + Image.asset( | |
99 | + 'lock'.assetPng, | |
100 | + height: 34.h, | |
101 | + width: 31.w, | |
102 | + ), | |
103 | + 18.5.horizontalSpace, | |
104 | + Expanded( | |
105 | + child: TextFieldCustomerWidget( | |
106 | + hitText: '请输入验证码', | |
107 | + bgImageName: 'Input_layer_down', | |
108 | + onChangeValue: (String value) { | |
109 | + bloc.add(CheckCodeChangeEvent()); | |
110 | + }, | |
111 | + textInputType: TextInputType.emailAddress, | |
112 | + controller: bloc.checkNumController, | |
113 | + ) | |
114 | + ), | |
115 | + 16.5.horizontalSpace, | |
116 | + GestureDetector( | |
117 | + onTap: () { | |
118 | + if (bloc.canSendSms) { | |
119 | + bloc.add(SendSmsCodeEvent()); | |
120 | + } | |
121 | + }, | |
122 | + child: Container( | |
123 | + decoration: BoxDecoration( | |
124 | + image: DecorationImage( | |
125 | + image: AssetImage( | |
126 | + bloc.canSendSms?'securitycode'.assetPng:'securitycode_dis'.assetPng | |
127 | + ), | |
128 | + fit: BoxFit.fill | |
129 | + ), | |
114 | 130 | ), |
115 | - ), | |
116 | - padding: const EdgeInsets.symmetric(horizontal:12.0,vertical: 15.0), | |
117 | - child: const Text( | |
131 | + padding: const EdgeInsets.symmetric(horizontal:12.0,vertical: 15.0), | |
132 | + child: const Text( | |
118 | 133 | '获取验证码', |
119 | - style: TextStyle( | |
120 | - fontSize: 16, | |
121 | - color: Colors.white | |
134 | + style: TextStyle( | |
135 | + fontSize: 16, | |
136 | + color: Colors.white | |
137 | + ), | |
122 | 138 | ), |
123 | 139 | ), |
124 | - ), | |
125 | - ) | |
126 | - ], | |
127 | - ) | |
128 | - ], | |
129 | - ) | |
130 | - ), | |
131 | - 2.verticalSpace, | |
132 | - Image.asset( | |
133 | - 'steven_bride'.assetPng, | |
134 | - height: 173.h, | |
135 | - width: 157.w, | |
136 | - ) | |
137 | - ], | |
138 | - ), | |
139 | - GestureDetector( | |
140 | - onTap: () { | |
141 | - if (bloc.canSetPwd) { | |
142 | - bloc.add(SetPassWordEvent()); | |
143 | - } | |
144 | - }, | |
145 | - child: Container( | |
146 | - decoration: BoxDecoration( | |
147 | - image: DecorationImage( | |
148 | - image: AssetImage( | |
149 | - bloc.canSetPwd?'login_enter'.assetPng:'login_enter_dis'.assetPng | |
150 | - ), | |
151 | - fit: BoxFit.fill | |
140 | + ) | |
141 | + ], | |
142 | + ) | |
143 | + ], | |
144 | + ) | |
152 | 145 | ), |
153 | - ), | |
154 | - padding: const EdgeInsets.symmetric( | |
155 | - horizontal: 28.0, | |
156 | - vertical: 14.0 | |
157 | - ), | |
158 | - child:const Text( | |
159 | - '确定', | |
160 | - style: TextStyle( | |
161 | - fontSize: 16 | |
146 | + 2.verticalSpace, | |
147 | + Image.asset( | |
148 | + 'steven_bride'.assetPng, | |
149 | + height: 173.h, | |
150 | + width: 157.w, | |
151 | + ) | |
152 | + ], | |
153 | + ), | |
154 | + GestureDetector( | |
155 | + onTap: () { | |
156 | + if (bloc.canSetPwd) { | |
157 | + bloc.add(SetPassWordEvent()); | |
158 | + } | |
159 | + }, | |
160 | + child: Container( | |
161 | + decoration: BoxDecoration( | |
162 | + image: DecorationImage( | |
163 | + image: AssetImage( | |
164 | + bloc.canSetPwd?'login_enter'.assetPng:'login_enter_dis'.assetPng | |
165 | + ), | |
166 | + fit: BoxFit.fill | |
167 | + ), | |
168 | + ), | |
169 | + padding: const EdgeInsets.symmetric( | |
170 | + horizontal: 28.0, | |
171 | + vertical: 14.0 | |
172 | + ), | |
173 | + child:const Text( | |
174 | + '确定', | |
175 | + style: TextStyle( | |
176 | + fontSize: 16 | |
177 | + ), | |
162 | 178 | ), |
163 | 179 | ), |
164 | - ), | |
165 | - ) | |
166 | - ], | |
167 | - ), | |
168 | - ) | |
169 | - ], | |
180 | + ) | |
181 | + ], | |
182 | + ), | |
183 | + ) | |
184 | + ], | |
185 | + ), | |
170 | 186 | ), |
171 | 187 | ), |
172 | - ), | |
173 | - ); | |
174 | - } | |
188 | + ); | |
189 | + } | |
175 | 190 | ); |
176 | 191 | } |
177 | 192 | \ No newline at end of file | ... | ... |
lib/login/loginpage/bloc/login_bloc.dart
... | ... | @@ -16,15 +16,11 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> { |
16 | 16 | bool _canLogin = false; |
17 | 17 | ///是否可以发送验证码 |
18 | 18 | bool _canSendSms = false; |
19 | - ///正在发送验证码 | |
20 | - bool _sendSmsIng = false; | |
21 | 19 | ///是否阅读协议 |
22 | 20 | bool _agreement = false; |
23 | 21 | ///登陆方式 |
24 | 22 | LoginType _loginType = LoginType.sms; |
25 | 23 | |
26 | - int _countDown = 0; | |
27 | - | |
28 | 24 | final TextEditingController phoneNumController = TextEditingController(); |
29 | 25 | final TextEditingController checkNumController = TextEditingController(); |
30 | 26 | |
... | ... | @@ -32,21 +28,19 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> { |
32 | 28 | bool get agreement => _agreement; |
33 | 29 | LoginType get loginType => _loginType; |
34 | 30 | bool get canSendSms => _canSendSms; |
35 | - bool get sendSmsIng => _sendSmsIng; | |
36 | 31 | |
37 | 32 | LoginBloc() : super(LoginInitial()) { |
38 | 33 | on<RequestLoginEvent>(_requestLoginApi); |
39 | 34 | on<ChangeLoginTypeEvent>(_changeLoginType); |
40 | 35 | on<PhoneNumChangeEvent>(_changePhoneNumber); |
41 | 36 | on<AgreementChangeEvent>(_agreementTypeChange); |
42 | - on<ForgetPasswordEvent>(_forgetPassword); | |
43 | 37 | on<CheckFieldChangeEvent>(_checkFiledChange); |
44 | 38 | } |
45 | 39 | |
46 | 40 | |
47 | 41 | ///请求登陆 |
48 | 42 | void _requestLoginApi(RequestLoginEvent event, Emitter<LoginState> emitter) async { |
49 | - | |
43 | + emitter(LoginResultChangeState()); | |
50 | 44 | } |
51 | 45 | |
52 | 46 | ///切换登陆方式 |
... | ... | @@ -100,11 +94,6 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> { |
100 | 94 | } |
101 | 95 | } |
102 | 96 | |
103 | - ///忘记密码 | |
104 | - void _forgetPassword(ForgetPasswordEvent event, Emitter<LoginState> emitter) async { | |
105 | - | |
106 | - } | |
107 | - | |
108 | 97 | ///登陆状态判断 |
109 | 98 | bool _loginStateChange() { |
110 | 99 | if (_agreement) { | ... | ... |
lib/login/loginpage/bloc/login_event.dart
... | ... | @@ -2,19 +2,13 @@ part of 'login_bloc.dart'; |
2 | 2 | |
3 | 3 | @immutable |
4 | 4 | abstract class LoginEvent {} |
5 | - | |
6 | -class RequestLoginEvent extends LoginEvent {} | |
7 | - | |
5 | +///切换登陆方式 | |
8 | 6 | class ChangeLoginTypeEvent extends LoginEvent {} |
9 | - | |
7 | +///输入手机号 | |
10 | 8 | class PhoneNumChangeEvent extends LoginEvent {} |
11 | - | |
9 | +///输入验证码/密码 | |
12 | 10 | class CheckFieldChangeEvent extends LoginEvent {} |
13 | - | |
11 | +///隐私协议点击 | |
14 | 12 | class AgreementChangeEvent extends LoginEvent {} |
15 | - | |
16 | -class ForgetPasswordEvent extends LoginEvent {} | |
17 | - | |
18 | -class CountDownEvent extends LoginEvent {} | |
19 | - | |
20 | -class CancelCountDownEvent extends LoginEvent {} | |
13 | +///请求登陆 | |
14 | +class RequestLoginEvent extends LoginEvent {} | ... | ... |
lib/login/loginpage/bloc/login_state.dart
... | ... | @@ -4,13 +4,13 @@ part of 'login_bloc.dart'; |
4 | 4 | abstract class LoginState {} |
5 | 5 | |
6 | 6 | class LoginInitial extends LoginState {} |
7 | - | |
7 | +///登陆按钮状态 | |
8 | 8 | class LoginEventChangeState extends LoginState {} |
9 | - | |
9 | +///切换登陆方式 | |
10 | 10 | class LoginTypeChangeState extends LoginState {} |
11 | - | |
11 | +///发送验证码按钮状态 | |
12 | 12 | class SmsSendTypeChangeState extends LoginState {} |
13 | - | |
13 | +///是否同意协议 | |
14 | 14 | class AgreementTypeChangeState extends LoginState {} |
15 | - | |
16 | -class CountDownNumChangeState extends LoginState {} | |
15 | +///登陆请求结果 | |
16 | +class LoginResultChangeState extends LoginState {} | ... | ... |
lib/login/loginpage/login_page.dart
1 | 1 | import 'package:flutter/gestures.dart'; |
2 | 2 | import 'package:flutter/material.dart'; |
3 | 3 | import 'package:flutter_bloc/flutter_bloc.dart'; |
4 | +import 'package:flutter_easyloading/flutter_easyloading.dart'; | |
4 | 5 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
5 | 6 | import 'package:wow_english/common/extension/string_extension.dart'; |
6 | 7 | import 'package:wow_english/common/widgets/textfield_customer_widget.dart'; |
... | ... | @@ -15,6 +16,20 @@ class LoginPage extends StatelessWidget { |
15 | 16 | Widget build(BuildContext context) { |
16 | 17 | return BlocProvider( |
17 | 18 | create: (context) => LoginBloc(), |
19 | + child: _LoginPageView(), | |
20 | + ); | |
21 | + } | |
22 | +} | |
23 | + | |
24 | +class _LoginPageView extends StatelessWidget { | |
25 | + @override | |
26 | + Widget build(BuildContext context) { | |
27 | + return BlocListener<LoginBloc,LoginState>( | |
28 | + listener: (context, state){ | |
29 | + if (state is LoginResultChangeState) { | |
30 | + EasyLoading.showToast('登陆接口回调'); | |
31 | + } | |
32 | + }, | |
18 | 33 | child: _buildLoginViewWidget(), |
19 | 34 | ); |
20 | 35 | } | ... | ... |
lib/login/loginpage/time_widget.dart
... | ... | @@ -4,57 +4,62 @@ import 'package:wow_english/common/blocs/timerbloc/timer_bloc.dart'; |
4 | 4 | import 'package:wow_english/common/extension/string_extension.dart'; |
5 | 5 | import 'package:wow_english/common/widgets/timer_ticker.dart'; |
6 | 6 | |
7 | -class TimerWidget extends StatefulWidget { | |
7 | +class TimerWidget extends StatelessWidget { | |
8 | 8 | const TimerWidget({super.key, required this.canSendSms}); |
9 | 9 | |
10 | 10 | final bool canSendSms; |
11 | 11 | |
12 | 12 | @override |
13 | - State<StatefulWidget> createState() { | |
14 | - return _TimerWidgetState(); | |
13 | + Widget build(BuildContext context) { | |
14 | + return BlocProvider( | |
15 | + create: (_) => TimerBloc(ticker: const TimerTicker()), | |
16 | + child: TimerWidgetView(canSendSms: canSendSms,), | |
17 | + ); | |
15 | 18 | } |
16 | 19 | } |
17 | 20 | |
18 | -class _TimerWidgetState extends State<TimerWidget> { | |
19 | - late bool sendSmsIng; | |
21 | +class TimerWidgetView extends StatelessWidget { | |
22 | + | |
23 | + final bool canSendSms; | |
24 | + | |
25 | + const TimerWidgetView({super.key, required this.canSendSms}); | |
20 | 26 | |
21 | - @override | |
22 | - void initState() { | |
23 | - super.initState(); | |
24 | - sendSmsIng = false; | |
25 | - } | |
26 | 27 | |
27 | 28 | @override |
28 | 29 | Widget build(BuildContext context) { |
29 | - return BlocProvider( | |
30 | - create: (_) => TimerBloc(ticker: const TimerTicker()), | |
31 | - child: _buildCountdownWidget(), | |
30 | + bool sendSmsIng = false; | |
31 | + return BlocListener<TimerBloc,TimerState>( | |
32 | + listener: (context, s) { | |
33 | + if (s is RunningState) { | |
34 | + sendSmsIng = true; | |
35 | + } if (s is FinishedState) { | |
36 | + sendSmsIng = false; | |
37 | + context.read<TimerBloc>().add(ResetEvent()); | |
38 | + } else { | |
39 | + sendSmsIng = false; | |
40 | + } | |
41 | + }, | |
42 | + child: _buildCountdownWidget(sendSmsIng:sendSmsIng), | |
32 | 43 | ); |
33 | 44 | } |
34 | 45 | |
35 | - Widget _buildCountdownWidget() => BlocBuilder<TimerBloc,TimerState>( | |
46 | + Widget _buildCountdownWidget({required bool sendSmsIng}) => BlocBuilder<TimerBloc,TimerState>( | |
36 | 47 | buildWhen: (prev, state) => prev.runtimeType != state.runtimeType, |
37 | 48 | builder: (context,state) { |
38 | 49 | final bloc = BlocProvider.of<TimerBloc>(context); |
39 | 50 | final duration = bloc.state.duration; |
40 | 51 | final secondsStr = (duration % 60).floor().toString().padLeft(2, '0'); |
41 | - if (state is TimerInitial) { | |
42 | - sendSmsIng = true; | |
43 | - } else { | |
44 | - sendSmsIng = false; | |
45 | - } | |
46 | 52 | return GestureDetector( |
47 | 53 | onTap: () { |
48 | - if (widget.canSendSms && !sendSmsIng) { | |
54 | + if (canSendSms && !sendSmsIng) { | |
49 | 55 | bloc.add(ResetEvent()); |
50 | - bloc.add(StartEvent(duration: bloc.state.duration)); | |
51 | 56 | } |
52 | 57 | }, |
53 | 58 | child: Container( |
54 | 59 | decoration: BoxDecoration( |
55 | 60 | image: DecorationImage( |
56 | 61 | image: AssetImage( |
57 | - widget.canSendSms?'securitycode'.assetPng:'securitycode_dis'.assetPng | |
62 | + canSendSms?'securitycode'.assetPng:'securitycode_dis'.assetPng | |
58 | 63 | ), |
59 | 64 | fit: BoxFit.fill |
60 | 65 | ), | ... | ... |
lib/login/setpwd/bloc/set_pwd_bloc.dart
... | ... | @@ -6,6 +6,8 @@ part 'set_pwd_state.dart'; |
6 | 6 | |
7 | 7 | class SetPwdBloc extends Bloc<SetPwdEvent, SetPwdState> { |
8 | 8 | |
9 | + final String? phoneNumber; | |
10 | + | |
9 | 11 | final TextEditingController passWordFirstController = TextEditingController(); |
10 | 12 | final TextEditingController passWordSecondController = TextEditingController(); |
11 | 13 | ///密码是否符合规则(第一个输入框) |
... | ... | @@ -31,7 +33,7 @@ class SetPwdBloc extends Bloc<SetPwdEvent, SetPwdState> { |
31 | 33 | |
32 | 34 | bool get ensure => _passwordCheck && _passwordEnsure; |
33 | 35 | |
34 | - SetPwdBloc() : super(SetPwdInitial()) { | |
36 | + SetPwdBloc(this.phoneNumber) : super(SetPwdInitial()) { | |
35 | 37 | on<PwdEnsureEvent>(_pwdEnsureTextChange); |
36 | 38 | on<PwdCheckEvent>(_pwdCheckTextChange); |
37 | 39 | on<SetPasswordEvent>(_setPassword); |
... | ... | @@ -114,6 +116,6 @@ class SetPwdBloc extends Bloc<SetPwdEvent, SetPwdState> { |
114 | 116 | } |
115 | 117 | |
116 | 118 | void _setPassword(SetPasswordEvent event,Emitter<SetPwdState> emitter) async { |
117 | - | |
119 | + emitter(PasswordSetSuccessState()); | |
118 | 120 | } |
119 | 121 | } | ... | ... |
lib/login/setpwd/bloc/set_pwd_state.dart
lib/login/setpwd/set_pwd_page.dart
... | ... | @@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; |
3 | 3 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
4 | 4 | import 'package:wow_english/common/extension/string_extension.dart'; |
5 | 5 | import 'package:wow_english/login/setpwd/bloc/set_pwd_bloc.dart'; |
6 | +import 'package:wow_english/route/route.dart'; | |
6 | 7 | |
7 | 8 | import '../../common/widgets/textfield_customer_widget.dart'; |
8 | 9 | |
... | ... | @@ -13,7 +14,21 @@ class SetPassWordPage extends StatelessWidget { |
13 | 14 | @override |
14 | 15 | Widget build(BuildContext context) { |
15 | 16 | return BlocProvider( |
16 | - create: (context) => SetPwdBloc(), | |
17 | + create: (context) => SetPwdBloc(phoneNum), | |
18 | + child: _SetPassWordPageView(), | |
19 | + ); | |
20 | + } | |
21 | +} | |
22 | + | |
23 | +class _SetPassWordPageView extends StatelessWidget { | |
24 | + @override | |
25 | + Widget build(BuildContext context) { | |
26 | + return BlocListener<SetPwdBloc, SetPwdState>( | |
27 | + listener: (context, s){ | |
28 | + if (s is PasswordSetSuccessState) { | |
29 | + Navigator.of(context).pushNamedAndRemoveUntil(AppRouteName.home, (route) => false); | |
30 | + } | |
31 | + }, | |
17 | 32 | child: _buildSetPwdView(), |
18 | 33 | ); |
19 | 34 | } |
... | ... | @@ -129,6 +144,7 @@ class SetPassWordPage extends StatelessWidget { |
129 | 144 | if (!bloc.ensure) { |
130 | 145 | return; |
131 | 146 | } |
147 | + bloc.add(SetPasswordEvent()); | |
132 | 148 | }, |
133 | 149 | child: Container( |
134 | 150 | decoration: BoxDecoration( | ... | ... |