Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic support #63

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

imsamgarg
Copy link

The current implementation restricts ValidationBuilder to be only used in the TextFormFields or wherever the value is in a string. There are some cases where we would need to validate values other than String like DropdownFormField or any custom FormField.

Consider this example

DatePickerFormField(
  onChanged: (v) {
    dueDate = v;
  },
  validator: (DateTime? date) {
    // date validations here...
  },
);

DatePickerFormField is a custom widget I made using FormField. the validator has this signature.

final FormFieldValidator<DateTime>? validator; 

I can not use the current ValidationBuilder in this case. To solve this I've added generics support to the original ValidationBuilder class and rename it to GenericValidationBuilder. To avoid breaking the old code I've added a typedef with the original class name.

// For backwards compatibility
typedef ValidationBuilder = GenericValidationBuilder<String>;
typedef StringValidationBuilder = GenericValidationBuilder<String>;

Please review the PR.

@themisir
Copy link
Owner

The issue is almost all of the validators in the library are only useful for string values. Adding generic validation support does not provide any value to the users since users will need to provide their own validation functions & messages, strictly limiting capabilities of the library for non string values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants