Blame view

lib/pages/login/setpwd/bloc/set_pwd_bloc.dart 3.61 KB
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
1
2
3
4
5
6
7
8
  import 'package:flutter/cupertino.dart';
  import 'package:flutter_bloc/flutter_bloc.dart';
  
  part 'set_pwd_event.dart';
  part 'set_pwd_state.dart';
  
  class SetPwdBloc extends Bloc<SetPwdEvent, SetPwdState> {
  
e1f36554   liangchengyou   feat:调整状态监听逻辑
9
    final String? phoneNumber;
65e33ae8   liangchengyou   feat:更新代码
10
11
    final String? code;
    final int? type;
e1f36554   liangchengyou   feat:调整状态监听逻辑
12
  
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
    final TextEditingController passWordFirstController = TextEditingController();
    final TextEditingController passWordSecondController = TextEditingController();
    ///密码是否符合规则(第一个输入框)
    bool _passwordEnsure = false;
    ///密码是否超过16位(第一个输入框)
    bool _passwordLarger = false;
    ///是否显示Icon(第一个输入框)
    bool _showPwdIcon = false;
    ///是否显示Icon(第二个输入框)
    bool _showCheckPwdIcon = false;
    ///密码是否一致
    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;
  
65e33ae8   liangchengyou   feat:更新代码
38
    SetPwdBloc(this.phoneNumber, this.code, this.type) : super(SetPwdInitial()) {
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
      on<PwdEnsureEvent>(_pwdEnsureTextChange);
      on<PwdCheckEvent>(_pwdCheckTextChange);
      on<SetPasswordEvent>(_setPassword);
    }
  
    void _pwdCheckTextChange(PwdCheckEvent event,Emitter<SetPwdState> emitter) async {
      if(passWordSecondController.text.isEmpty) {
        _showCheckPwdIcon = false;
        emitter(PasswordCheckIconShowState());
      } else {
        if (!_showCheckPwdIcon) {
          _showCheckPwdIcon = true;
          emitter(PasswordCheckIconShowState());
        }
      }
      if(passWordFirstController.text == passWordSecondController.text) {
        _passwordCheck = true;
        emitter(SetCheckPwdState());
      } else {
        _passwordCheck = false;
        emitter(SetCheckPwdState());
      }
    }
  
    void _pwdEnsureTextChange(PwdEnsureEvent event,Emitter<SetPwdState> emitter) async {
      if (passWordFirstController.text.isEmpty) {
        if (_showPwdIcon) {
          _showPwdIcon = false;
          emitter(PasswordIconShowState());
        }
      } else {
        if (!_showPwdIcon) {
          _showPwdIcon = true;
          emitter(PasswordIconShowState());
        }
        if(passWordSecondController.text.isNotEmpty) {
          if (passWordFirstController.text == passWordSecondController.text) {
            _passwordCheck = true;
  
          } else {
            _passwordCheck = false;
          }
          emitter(SetCheckPwdState());
        }
        if (passWordFirstController.text.length >= 8 && passWordFirstController.text.length <=16) {
          ///符合密码要求
          if(!_passwordEnsure) {
            _passwordEnsure = true;
            emitter(SetEnsurePwdState());
          }
          if(passWordSecondController.text.isNotEmpty) {
            if (passWordFirstController.text == passWordSecondController.text) {
  
            }
          }
          if (_passwordLarger) {
            _passwordLarger = false;
            emitter(PasswordLargeState());
          }
        } else {
          if(passWordFirstController.text.length > 16) {
            ///超过十六位
            if (!_passwordLarger) {
              _passwordLarger = true;
              emitter(PasswordLargeState());
            }
          } else {
            if (_passwordLarger) {
              _passwordLarger = false;
              emitter(PasswordLargeState());
            }
          }
          ///密码不符合要求
          if(_passwordEnsure) {
            _passwordEnsure = false;
            emitter(SetEnsurePwdState());
          }
        }
      }
    }
  
    void _setPassword(SetPasswordEvent event,Emitter<SetPwdState> emitter) async {
e1f36554   liangchengyou   feat:调整状态监听逻辑
121
      emitter(PasswordSetSuccessState());
1d5315dd   liangchengyou   feat:添加字体,调整文件结构
122
123
    }
  }