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

onSaved and validator error #2

Open
rodrigobastosv opened this issue Oct 2, 2019 · 3 comments
Open

onSaved and validator error #2

rodrigobastosv opened this issue Oct 2, 2019 · 3 comments

Comments

@rodrigobastosv
Copy link

When i set an initial value (because i want the field to be with a initial value) when i validate or save the form i get an error because the value received by the onSaved or validator is null.

This is probably happening because when i set an initial value the onChanged method is not being called and the value is not being updated internally.

Besides this error, this is a great component. Thanks a lot for you effort

@javiermrz
Copy link

javiermrz commented Apr 2, 2020

Same issue here. Did you find any workaround?

@javiermrz
Copy link

javiermrz commented Apr 2, 2020

Okey, just solved it. Just edit the component file, and include the initial value in the widget properties. Then, pass that onto the super call:

class DropDownFormField extends FormField<dynamic> {
  final String titleText;
  final String hintText;
  final bool required;
  final String errorText;
  final dynamic value;
  final dynamic initialValue;
  final List dataSource;
  final String textField;
  final String valueField;
  final Function onChanged;

  DropDownFormField(
      {FormFieldSetter<dynamic> onSaved,
      FormFieldValidator<dynamic> validator,
      bool autovalidate = false,
      this.titleText = 'Title',
      this.hintText = 'Select one option',
      this.required = false,
      this.errorText = 'Please select one option',
      this.initialValue,
      this.value,
      this.dataSource,
      this.textField,
      this.valueField,
      this.onChanged})
      : super(
          onSaved: onSaved,
          validator: validator,
          initialValue: initialValue,
          autovalidate: autovalidate,
          builder: (FormFieldState<dynamic> state) {
            return Container(
              child: Column(
...

And just use that initialValue from outside as you would with any other TextFormField.


To the contributors: Thanks for the component, its really nice to have this. It seems, however, that this package is abandoned. It would be nice if you could update it with this solution, as it only needs literally 3 new lines, and it solves a great flaw.

Cheers!

@shivanshtalwar0
Copy link

kindly use DropDownButtonFormField
which is the official version of the very same plugin as this plugin has issues like the state of form field doesn't update programmatically.

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

No branches or pull requests

3 participants