themisir / form-validator

Simplest form validation for flutter form widgets
https://pub.dev/packages/form_validator
MIT License
77 stars 39 forks source link

Added support for all data type validation #53

Closed pratham-sarankar closed 1 year ago

pratham-sarankar commented 1 year ago

Fixes #47

The dropdown widget uses value parameters to differentiate between different items. This value parameter can be of any data type. For example, we preferred an integer value for every dropdown menu item.

Here, it was suggested to use DropdownButtonFormField\. I think users of this package must be free to use any data type, not just String.

This update will enable the option to use it like ValidationBuilder\().build();

themisir commented 1 year ago

What's the point of using validator package that does string validation on a non-string data type. Only required option will work and all the other validators won't work or behave unexpectedly. I am not against this feature but it seems pointless to me.

However, as I said I am not completely against it, I just don't see any value. If there's something I am missing, I would be more than happy to explore them :)

pratham-sarankar commented 1 year ago
Screenshot 2023-01-02 at 1 11 36 AM Screenshot 2023-01-02 at 1 12 52 AM

Basically, this is the issue, I faced and decided to fix it. DropDownMenuItem in our case will have int? value. It will be the id of the data table. Nothing else in the table is unique. I know there is a workaround. I can just call toString method in id. But it will be good if the library fix it for me.

I actually understand your point. So, at the minimum we can change two lines of code and it will at least accept all data types.

1st

typedef StringValidationCallback = String? Function(T? value);

2nd

String? test(var value)

themisir commented 1 year ago

You can write an extension like:

extension on ValidationBuilder {
  String? Function(dynamic) buildDyn() {
    return (value) {
      return this.test(value?.toString());
    };
  }
}

And consume it like so:

validator: ValidationBuilder().buildDyn()

I get all your concerns, and unfortunately I can not agree to add such feature. Even though it doesn't look like too much, doing so will provide an ABI that's a potential for a future incompatibility or more mis-understanding & confusion. That's why I am committed to keeping the scope of the validator in control. Half implementing something will create confusion and inconsistency that doesn't usually end well.

pratham-sarankar commented 1 year ago

Alright, I get you! So, lemme just close the request.