joanpablo / reactive_forms

This is a model-driven approach to handling form inputs and validations, heavily inspired in Angular's Reactive Forms
MIT License
465 stars 86 forks source link

ReactiveFormConsumer not updating #191

Closed cedvdb closed 2 years ago

cedvdb commented 3 years ago

I believe there is a problem where the ReactiveFormConsumer is not updating correctly.

If I listen to the form status changes I can see the form is valid:

  ProfileForm({
    required this.onSubmit,
  }) {
    formGroup.statusChanged.listen((event) {
      print(event);
    });
  }

while in the ReactiveFormConsumer the form is always invalid. and the build method is only called at the start.

          ReactiveFormConsumer(
            builder: (_, form, __) {
              return ElevatedButton(
                onPressed: form.valid ? () => onSubmit(form.value) : null,
                child: Text('Submit'),
              );
            },
          )
cedvdb commented 2 years ago

Just to be clear, my FormGroup status change emits, while the ReactiveFormConsumer does not call it's builder.

Any idea why that could be the case ? Once I change the key of the ReactiveForm it starts working again, then on the next hot reload the builder method is not called anymore.

It's like the inheritedStream or whatever is used at the top stops sending notifications.

Any pointers to help me find the root cause given the key hint ?

cedvdb commented 2 years ago

switching to stateful widget resolves this

alejandrogiubel commented 2 years ago

I have the same issue. But stateful widget not solve my problem. Change the key of the ReactiveForm works but I lost the widget state when push new route and the form restart. Defining the form inside my Cubit, it works ok. In this case solve my problem but in others cases where I need the context for translations I can`t use this workaround. Any advise?