I have 4 textformfield. One for email, username, and 2 password fields. They all have proper validation. Except for the password field where I want to check if the 2 passwords are the same. Not sure how to do that part. I also have a register button I want to gather input from those 4 textform field and send it to the register button to sign up a new account using firebase. How do i get my register button to accept those form outputs?
flutter - how to submit textformfield to a sign up button?
2.6k views Asked by pizzaman2020 AtThere are 3 answers
For checking if both the password and confirm passwords are the same u may have to add a conditional part in the validation of the form.
You can register a user like this:
String _email;
String _password; //add these two to the validation and set the value state = to these fields respectively.
try {
UserCredential userCredential = await
FirebaseAuth.instance.createUserWithEmailAndPassword(
email: _email,
password: _password
);
} on FirebaseAuthException catch (e) {
if (e.code == 'weak-password') {
print('The password provided is too weak.');
} else if (e.code == 'email-already-in-use') {
print('The account already exists for that email.');
}
} catch (e) {
print(e);
}
For more information refer this
you can use variable assigned to each textformfield as a value property and assign new value to them with onchanged method existing in textformfield. Something like this:
TextFormField( value: _password, onchange: (val) { _password = val; } )
Or use controller for textformfield and get their value on submit:
TextFormField( controller: _controller )
Now, on button you can execute your functionality or call a method which has the functionality:
RaisedButton ( onPressed: () { /// Getting data from the controller attached to textformfield String password = _controller.text;
//// Firebase auth code here. } )
You can add controller to four of your
TextField
.When submit button is clicked, you can get the value by this