If you want to validate form asynchronously in flutter? At this time I think that you can’t associate a Future to a validator.
What you can do is this verifying the data on a button click or in another way and set the state on the validator response var.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | @override Widget build(BuildContext context) { // TODO: implement build return Scaffold( body: Form( key: _formKey, child: Column(children: [ new TextFormField( validator: (value) { return usernameValidator; }, decoration: InputDecoration(hintText: 'Username')), RaisedButton( onPressed: () async { var response = await checkUser(); setState(() { this.usernameValidator = response; }); if (_formKey.currentState.validate()) {} }, child: Text('Submit'), ) ]))); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.