shiang / flutter-form-with-validation-BLOC

This form and validation functions are created by using the BLOC pattern with RxDart instead of using StatefulWidget
63 stars 16 forks source link

How to show validation on submit? #2

Open ssatz opened 5 years ago

ssatz commented 5 years ago

How to show validation on submit?

submit() {
    final validEmail = _emailController.value;
    final validPassword = _passwordController.value;

    print('Email is $validEmail, and password is $validPassword');
  }
fr4nk-dev commented 4 years ago

Try this, or add more validations for example min lenght or something else

submit() {
    if (email.length == 0) {
      _emailController.sink.addError('This field cannot be empty');
    }

    if (pass.length == 0) {
      _passController.sink.addError('This field cannot be empty');
    }
  }