I am having the same problem as the poster in this question: flutter validate form asynchronously.
However, I'm having trouble implementing this and understand how the validation is working.
First, what does this code return? Does this return a boolean?
Future checkUser() async {
var user = await Firestore.instance
.collection('users')
.document(userNameController.text)
.get();
return user.exists;
Second, what is the userNameValidator in this case? Is this a boolean?
new TextFormField(
validator: (value) {
return usernameValidator;
},
Thanks, for the help.
The method checkUser
will begin a call to Firebase. The await
keyword is telling the compiler that we need the output of that call, but there is no need to block everything else from running. After the call has been made, the function will return a bool indicating if the given user exists.
On the other question checkUser
is called via the onPressed
call which waits for a return value and assigns it to the usernameValidator
variable - therefore making it a bool.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With