Blame view

lib/pages/login/setpwd/set_pwd_page.dart 9.74 KB
c9df43c8   Key   feat: 修改个人信息、接口
1
  import 'package:flutter/cupertino.dart';
4bf67b91   liangchengyou   feat:设置密码
2
3
4
5
  import 'package:flutter/material.dart';
  import 'package:flutter_bloc/flutter_bloc.dart';
  import 'package:flutter_screenutil/flutter_screenutil.dart';
  import 'package:wow_english/common/extension/string_extension.dart';
4b358e22   liangchengyou   feat:调整文件结构
6
  import 'package:wow_english/common/widgets/textfield_customer_widget.dart';
e1f36554   liangchengyou   feat:调整状态监听逻辑
7
  import 'package:wow_english/route/route.dart';
4b2c2f07   Key   feat: 三种修改密码的类型及接口
8
  import 'package:wow_english/utils/toast_util.dart';
4bf67b91   liangchengyou   feat:设置密码
9
  
4b358e22   liangchengyou   feat:调整文件结构
10
11
  import 'bloc/set_pwd_bloc.dart';
  
c61b3c1a   Key   feat: toast_util....
12
13
  enum SetPwdPageType {
    /// 第一次设置密码
4b2c2f07   Key   feat: 三种修改密码的类型及接口
14
    initPwd,
c61b3c1a   Key   feat: toast_util....
15
16
17
18
  
    /// 忘记重设密码,必传手机号和验证码
    resetPwd,
  
da82bd70   Key   feat: user_inform...
19
    /// 修改密码,必传手机号和验证码,现在和忘记密码走一样的流程
c61b3c1a   Key   feat: toast_util....
20
21
    changePwd,
  }
4bf67b91   liangchengyou   feat:设置密码
22
  
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
23
  class SetPassWordPage extends StatelessWidget {
c61b3c1a   Key   feat: toast_util....
24
25
26
    const SetPassWordPage({super.key, this.phoneNum, this.smsCode, required this.pageType});
  
    final SetPwdPageType pageType;
4bf67b91   liangchengyou   feat:设置密码
27
    final String? phoneNum;
c61b3c1a   Key   feat: toast_util....
28
    final String? smsCode;
4bf67b91   liangchengyou   feat:设置密码
29
30
31
  
    @override
    Widget build(BuildContext context) {
4bf67b91   liangchengyou   feat:设置密码
32
      return BlocProvider(
c61b3c1a   Key   feat: toast_util....
33
        create: (context) => SetPwdBloc(phoneNum, smsCode, pageType),
e1f36554   liangchengyou   feat:调整状态监听逻辑
34
35
36
        child: _SetPassWordPageView(),
      );
    }
c61b3c1a   Key   feat: toast_util....
37
  
c9df43c8   Key   feat: 修改个人信息、接口
38
    /// [pageType]= [resetPwd] or [changePwd] 时,必传手机号和验证码
c61b3c1a   Key   feat: toast_util....
39
    static push(BuildContext context, SetPwdPageType pageType, {String? phoneNum, String? smsCode}) {
c9df43c8   Key   feat: 修改个人信息、接口
40
41
42
43
44
45
46
      Navigator.of(context).push(CupertinoPageRoute(builder: (context) {
        return SetPassWordPage(
          phoneNum: phoneNum,
          smsCode: smsCode,
          pageType: pageType,
        );
      }));
c61b3c1a   Key   feat: toast_util....
47
    }
e1f36554   liangchengyou   feat:调整状态监听逻辑
48
49
50
  }
  
  class _SetPassWordPageView extends StatelessWidget {
c61b3c1a   Key   feat: toast_util....
51
52
    late final SetPwdBloc bloc;
  
e1f36554   liangchengyou   feat:调整状态监听逻辑
53
54
    @override
    Widget build(BuildContext context) {
c61b3c1a   Key   feat: toast_util....
55
      bloc = BlocProvider.of<SetPwdBloc>(context);
e1f36554   liangchengyou   feat:调整状态监听逻辑
56
      return BlocListener<SetPwdBloc, SetPwdState>(
4b2c2f07   Key   feat: 三种修改密码的类型及接口
57
58
59
60
61
62
63
        listener: (context, state) {
          if (state is PasswordSetSuccessState) {
            if (bloc.pageType == SetPwdPageType.initPwd) {
              showToast('密码设置成功');
            } else {
              showToast('密码修改成功');
            }
08a0f5a8   liangchengyou   feat:路由方式更新
64
            pushNamedAndRemoveUntil(AppRouteName.home, (route) => false);
4b2c2f07   Key   feat: 三种修改密码的类型及接口
65
66
          } else if (state is PasswordSetFailedState) {
            state.message.toast();
e1f36554   liangchengyou   feat:调整状态监听逻辑
67
68
          }
        },
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
69
70
71
72
        child: _buildSetPwdView(),
      );
    }
  
c61b3c1a   Key   feat: toast_util....
73
    String _getTipsText() {
da82bd70   Key   feat: user_inform...
74
      String text = '接下来请设置一下您的新密码吧!';
c61b3c1a   Key   feat: toast_util....
75
76
  
      switch (bloc.pageType) {
4b2c2f07   Key   feat: 三种修改密码的类型及接口
77
        case SetPwdPageType.initPwd:
c61b3c1a   Key   feat: toast_util....
78
79
80
81
82
83
84
85
86
87
88
          text = '欢迎登录wow english\n接下来请设置一下您的密码吧!';
          break;
        case SetPwdPageType.resetPwd:
        case SetPwdPageType.changePwd:
          text = '修改密码\n接下来请设置一下您的新密码吧!';
          break;
      }
      return text;
    }
  
    Widget _buildSetPwdView() => BlocBuilder<SetPwdBloc, SetPwdState>(builder: (context, state) {
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
89
90
91
92
93
          return Scaffold(
            body: Container(
              color: Colors.white,
              child: SafeArea(
                child: ListView(
4bf67b91   liangchengyou   feat:设置密码
94
                  children: [
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
95
96
97
98
99
100
101
102
103
104
105
106
107
                    Padding(
                      padding: EdgeInsets.symmetric(horizontal: 40.w),
                      child: Column(
                        children: [
                          34.verticalSpace,
                          Row(
                            children: [
                              Image.asset(
                                'wow_logo'.assetPng,
                                height: 49.w,
                                width: 83.5.h,
                              ),
                              12.5.horizontalSpace,
f0d56772   liangchengyou   feat:更新尺寸适配
108
                              Text(
c61b3c1a   Key   feat: toast_util....
109
110
                                _getTipsText(),
                                style: TextStyle(fontSize: 16.5.sp, color: const Color(0xFF666666)),
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
111
112
                              )
                            ],
4bf67b91   liangchengyou   feat:设置密码
113
                          ),
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
114
115
                          Row(
                            crossAxisAlignment: CrossAxisAlignment.start,
4bf67b91   liangchengyou   feat:设置密码
116
                            children: [
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
117
118
119
120
121
122
123
124
125
                              Expanded(
                                child: Column(
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  children: [
                                    43.verticalSpace,
                                    Row(
                                      children: [
                                        Expanded(
                                            child: TextFieldCustomerWidget(
c61b3c1a   Key   feat: toast_util....
126
127
128
129
130
131
132
133
                                          height: 55.h,
                                          hitText: '请输入八位以上密码',
                                          bgImageName: 'Input_layer_up',
                                          controller: bloc.passWordFirstController,
                                          obscureText: true,
                                          textInputType: TextInputType.emailAddress,
                                          onChangeValue: (String value) => bloc.add(PwdEnsureEvent()),
                                        )),
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
134
135
                                        10.horizontalSpace,
                                        Opacity(
c61b3c1a   Key   feat: toast_util....
136
                                          opacity: bloc.showPwdIcon ? 1 : 0,
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
137
                                          child: Image.asset(
c61b3c1a   Key   feat: toast_util....
138
                                            bloc.passwordEnsure ? 'login_pass'.assetPng : 'login_error'.assetPng,
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
139
140
141
142
143
                                            height: 30,
                                            width: 30,
                                          ),
                                        )
                                      ],
4bf67b91   liangchengyou   feat:设置密码
144
                                    ),
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
145
146
147
148
                                    9.verticalSpace,
                                    Offstage(
                                      offstage: !bloc.passwordLarger,
                                      child: const Text('您已达到密码最大输入数,请妥善调整密码'),
4bf67b91   liangchengyou   feat:设置密码
149
                                    ),
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
150
151
152
153
154
                                    9.verticalSpace,
                                    Row(
                                      children: [
                                        Expanded(
                                            child: TextFieldCustomerWidget(
c61b3c1a   Key   feat: toast_util....
155
156
157
158
159
160
161
162
                                          height: 55.h,
                                          hitText: '请再次输入相同密码',
                                          bgImageName: 'Input_layer_up',
                                          obscureText: true,
                                          textInputType: TextInputType.emailAddress,
                                          controller: bloc.passWordSecondController,
                                          onChangeValue: (String value) => bloc.add(PwdCheckEvent()),
                                        )),
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
163
164
                                        10.horizontalSpace,
                                        Opacity(
c61b3c1a   Key   feat: toast_util....
165
                                          opacity: bloc.showCheckPwdIcon ? 1 : 0,
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
166
                                          child: Image.asset(
c61b3c1a   Key   feat: toast_util....
167
                                            bloc.passwordCheck ? 'login_pass'.assetPng : 'login_error'.assetPng,
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
168
169
170
171
172
173
174
175
176
                                            height: 30,
                                            width: 30,
                                          ),
                                        )
                                      ],
                                    ),
                                    9.verticalSpace,
                                    Offstage(
                                      offstage: bloc.passwordCheck,
f0d56772   liangchengyou   feat:更新尺寸适配
177
                                      child: Text(
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
178
                                        '请确认两次输入的密码是否一致',
c61b3c1a   Key   feat: toast_util....
179
                                        style: TextStyle(fontSize: 16.sp, color: const Color(0xFF333333)),
4bf67b91   liangchengyou   feat:设置密码
180
181
                                      ),
                                    ),
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
182
183
184
185
186
187
188
189
                                    Row(
                                      mainAxisAlignment: MainAxisAlignment.end,
                                      children: [
                                        GestureDetector(
                                          onTap: () {
                                            if (!bloc.ensure) {
                                              return;
                                            }
e1f36554   liangchengyou   feat:调整状态监听逻辑
190
                                            bloc.add(SetPasswordEvent());
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
191
192
193
194
195
                                          },
                                          child: Container(
                                            decoration: BoxDecoration(
                                              image: DecorationImage(
                                                  image: AssetImage(
c61b3c1a   Key   feat: toast_util....
196
197
                                                      bloc.ensure ? 'login_enter'.assetPng : 'login_enter_dis'.assetPng),
                                                  fit: BoxFit.fill),
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
198
                                            ),
c61b3c1a   Key   feat: toast_util....
199
                                            padding: EdgeInsets.symmetric(horizontal: 28.w, vertical: 14.h),
f0d56772   liangchengyou   feat:更新尺寸适配
200
                                            child: Text(
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
201
                                              '确定',
c61b3c1a   Key   feat: toast_util....
202
                                              style: TextStyle(color: Colors.white, fontSize: 16.sp),
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
203
204
205
206
207
208
209
210
211
212
213
214
215
216
                                            ),
                                          ),
                                        ),
                                        50.horizontalSpace
                                      ],
                                    )
                                  ],
                                ),
                              ),
                              30.horizontalSpace,
                              Image.asset(
                                'steven'.assetPng,
                                height: 254.h,
                                width: 100.w,
4bf67b91   liangchengyou   feat:设置密码
217
218
219
                              )
                            ],
                          ),
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
220
221
222
                        ],
                      ),
                    )
4bf67b91   liangchengyou   feat:设置密码
223
224
225
226
                  ],
                ),
              ),
            ),
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
227
          );
c61b3c1a   Key   feat: toast_util....
228
229
        });
  }