Blame view

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