Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter async form validation

Tags:

flutter

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.

like image 760
PJQuakJag Avatar asked Oct 16 '25 20:10

PJQuakJag


1 Answers

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.

like image 75
Zroq Avatar answered Oct 18 '25 14:10

Zroq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!