Flutter-Bloc-比较两个TextFields密码和passwordConfirm的问题

问题描述

我是个扑朔迷离的乞er。我正在使用Bloc,并且能够验证单个Texfield,但是我对尝试比较两个TextField(password和passwordConfirm)存在一些疑问。我将BehaviorSubject()用作控制器和Rx.dart,但找不到链接它们的方法。我也尝试使用StreamTransformer,但输入的值不能超过一个

(0,

这是其余的代码(register_page.dart,register_bloc.dart和validators.dart的一部分):

for i in range(3):
    B1 = A.copy()           //this line will make sense for kremer's rule
    B1[:,i] = b
    solution.append(np.linalg.det(B1)/np.linalg.det(A))
print(solution)
final validatePasswordConfirm = StreamTransformer<String,String>
   .fromHandlers(handleData: (passwordConfirm,sink) {});
// register_page.dart
    
Widget create_password(RegisterBloc bloc){
        return StreamBuilder(
            stream: bloc.passwordStream,builder: (BuildContext context,AsyncSnapshot snapshot) {
              return Container(
                padding: EdgeInsets.symmetric(horizontal: 20.0),child: TextField(
                  obscureText: true,decoration: Inputdecoration(
                      icon: Icon(Icons.lock,color: Colors.deepPurple),labelText: 'password',counterText: snapshot.data,errorText: snapshot.error
                  ),onChanged: (value) => bloc.changePassword(value),),);
            },);
      }
    
      Widget create_password_confirm(RegisterBloc bloc){
        return StreamBuilder(
          stream: bloc.validatePasswordConfirmStream,AsyncSnapshot snapshot) {
            return Container(
              padding: EdgeInsets.symmetric(horizontal: 20.0),child: TextField(
                obscureText: true,decoration: Inputdecoration(
                    icon: Icon(Icons.lock,labelText: 'password Confirm',errorText: snapshot.error
                ),onChanged: (value) => bloc.changePasswordConfirm(value),);
          },);
      }

先谢谢您,我的英语不好。 马里亚诺问候

解决方法

最后几个小时后,我可以找到我的问题的答案。现在,我可以比较两个textField,如果它们彼此不匹配,我会向passwordConfirm textField发送一条错误消息。

Stream<String> get passwordConfirmStream => _passwordConfirmController.stream
      .transform(validatePassword).doOnData((String c){
    if (0 != _passwordController.value.compareTo(c)){
      _passwordConfirmController.addError("No Match");
    }
  }); 

问候,马里亚诺