1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
1
2
|
import 'package:flutter/cupertino.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
3
4
5
|
import 'package:wow_english/common/request/dao/user_dao.dart';
import 'package:wow_english/common/request/exception.dart';
import 'package:wow_english/utils/loading.dart';
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
6
|
|
c61b3c1a
Key
feat: toast_util....
|
7
8
|
import '../set_pwd_page.dart';
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
9
10
11
12
|
part 'set_pwd_event.dart';
part 'set_pwd_state.dart';
class SetPwdBloc extends Bloc<SetPwdEvent, SetPwdState> {
|
e1f36554
liangchengyou
feat:调整状态监听逻辑
|
13
|
final String? phoneNumber;
|
c61b3c1a
Key
feat: toast_util....
|
14
15
|
final String? smsCode;
late final SetPwdPageType pageType;
|
e1f36554
liangchengyou
feat:调整状态监听逻辑
|
16
|
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
17
18
|
final TextEditingController passWordFirstController = TextEditingController();
final TextEditingController passWordSecondController = TextEditingController();
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
19
|
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
20
21
|
///密码是否符合规则(第一个输入框)
bool _passwordEnsure = false;
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
22
|
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
23
24
|
///密码是否超过16位(第一个输入框)
bool _passwordLarger = false;
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
25
|
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
26
27
|
///是否显示Icon(第一个输入框)
bool _showPwdIcon = false;
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
28
|
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
29
30
|
///是否显示Icon(第二个输入框)
bool _showCheckPwdIcon = false;
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
31
|
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
///密码是否一致
bool _passwordCheck = true;
bool get passwordEnsure => _passwordEnsure;
bool get passwordCheck => _passwordCheck;
bool get passwordLarger => _passwordLarger;
bool get showPwdIcon => _showPwdIcon;
bool get showCheckPwdIcon => _showCheckPwdIcon;
bool get ensure => _passwordCheck && _passwordEnsure;
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
47
48
|
String get passwordText => passWordFirstController.text;
|
c61b3c1a
Key
feat: toast_util....
|
49
|
SetPwdBloc(this.phoneNumber, this.smsCode, this.pageType) : super(SetPwdInitial()) {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
50
51
52
53
54
|
on<PwdEnsureEvent>(_pwdEnsureTextChange);
on<PwdCheckEvent>(_pwdCheckTextChange);
on<SetPasswordEvent>(_setPassword);
}
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
55
56
|
void _pwdCheckTextChange(PwdCheckEvent event, Emitter<SetPwdState> emitter) async {
if (passWordSecondController.text.isEmpty) {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
57
58
59
60
61
62
63
64
|
_showCheckPwdIcon = false;
emitter(PasswordCheckIconShowState());
} else {
if (!_showCheckPwdIcon) {
_showCheckPwdIcon = true;
emitter(PasswordCheckIconShowState());
}
}
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
65
|
if (passWordFirstController.text == passWordSecondController.text) {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
66
67
68
69
70
71
72
73
|
_passwordCheck = true;
emitter(SetCheckPwdState());
} else {
_passwordCheck = false;
emitter(SetCheckPwdState());
}
}
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
74
|
void _pwdEnsureTextChange(PwdEnsureEvent event, Emitter<SetPwdState> emitter) async {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
75
76
77
78
79
80
81
82
83
84
|
if (passWordFirstController.text.isEmpty) {
if (_showPwdIcon) {
_showPwdIcon = false;
emitter(PasswordIconShowState());
}
} else {
if (!_showPwdIcon) {
_showPwdIcon = true;
emitter(PasswordIconShowState());
}
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
85
|
if (passWordSecondController.text.isNotEmpty) {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
86
87
|
if (passWordFirstController.text == passWordSecondController.text) {
_passwordCheck = true;
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
88
89
90
91
92
|
} else {
_passwordCheck = false;
}
emitter(SetCheckPwdState());
}
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
93
|
if (passWordFirstController.text.length >= 8 && passWordFirstController.text.length <= 16) {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
94
|
///符合密码要求
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
95
|
if (!_passwordEnsure) {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
96
97
98
|
_passwordEnsure = true;
emitter(SetEnsurePwdState());
}
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
99
100
|
if (passWordSecondController.text.isNotEmpty) {
if (passWordFirstController.text == passWordSecondController.text) {}
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
101
102
103
104
105
106
|
}
if (_passwordLarger) {
_passwordLarger = false;
emitter(PasswordLargeState());
}
} else {
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
107
|
if (passWordFirstController.text.length > 16) {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
108
109
110
111
112
113
114
115
116
117
118
|
///超过十六位
if (!_passwordLarger) {
_passwordLarger = true;
emitter(PasswordLargeState());
}
} else {
if (_passwordLarger) {
_passwordLarger = false;
emitter(PasswordLargeState());
}
}
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
119
|
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
120
|
///密码不符合要求
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
121
|
if (_passwordEnsure) {
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
122
123
124
125
126
127
128
|
_passwordEnsure = false;
emitter(SetEnsurePwdState());
}
}
}
}
|
4b2c2f07
Key
feat: 三种修改密码的类型及接口
|
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
/// 设置密码,调接口
void _setPassword(SetPasswordEvent event, Emitter<SetPwdState> emitter) async {
try {
await loading(() async {
switch (pageType) {
case SetPwdPageType.changePwd:
await UserDao.changePassword(passwordText);
break;
case SetPwdPageType.initPwd:
await UserDao.initPassword(passwordText);
break;
case SetPwdPageType.resetPwd:
if (phoneNumber == null || phoneNumber!.isEmpty) {
throw ApiException(ApiException.customErrorCode, '手机号为空');
}
if (smsCode == null || smsCode!.isEmpty) {
throw ApiException(ApiException.customErrorCode, '验证码为空');
}
await UserDao.resetPassword(phoneNumber!, passwordText, smsCode!);
break;
}
});
emitter(PasswordSetSuccessState());
} catch (e) {
String msg;
if (e is ApiException) {
msg = e.message ?? '未知错误';
} else {
msg = e.toString();
}
emitter(PasswordSetFailedState(msg));
}
|
1d5315dd
liangchengyou
feat:添加字体,调整文件结构
|
161
162
|
}
}
|