codegrue / card_settings

A flutter package for building card based forms.
https://pub.dartlang.org/packages/card_settings
MIT License
555 stars 103 forks source link

Async validation #144

Closed acamenhas closed 4 years ago

acamenhas commented 4 years ago

Hi, I have a CardSettingsText field that needs to check if the entered value is not duplicate (on the database). How can I do an async validation and show the error message on that field?

Thank you!

codegrue commented 4 years ago

In the validation callback, you would take the returned value, do your lookup, and if they don't match you would provide an error string.

  validator: (value) {
    if (!isInDatabase(value)) return 'Invalid text.';
    return null;
  },

isInDatabase would be whatever lookup method is needed for your persistence platform.