artflutter / reactive_forms_generator

Other
89 stars 22 forks source link

Using canPop/onPopInvoked causes FormControlParentNotFoundException #162

Closed TrplM closed 1 month ago

TrplM commented 4 months ago

Using canPop or onPopInvoked throws FormControlParentNotFoundException: ReactiveFormField widget couldn't find a parent widget. An instance of ReactiveFormConsumer widget must be under a ReactiveForm or a ReactiveFormArray in the widgets tree.

Example

dependencies:
  reactive_forms: ^17.0.1
  reactive_forms_annotations: ^5.0.0

dev_dependencies:
  build_runner: ^2.4.9
  reactive_forms_generator: ^5.0.1
@Rf()
class Basic {
  final String email;

  Basic({
    @RfControl() this.email = '',
  });
}

class Repro extends StatelessWidget {
  const Repro({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: BasicFormBuilder(
        // setup form model with initial data
        model: Basic(),
        canPop: (formGroup) => true,
        onPopInvoked: (formGroup, didPop) => {},
        // form builder
        builder: (context, formModel, child) {
          return Column(
            children: [
              ReactiveTextField<String>(
                formControl: formModel.emailControl,
                decoration: const InputDecoration(labelText: 'Email'),
              ),
              const SizedBox(height: 8.0),
              ReactiveBasicFormConsumer(
                builder: (context, form, child) {
                  return ElevatedButton(
                    onPressed: form.form.valid
                        ? () {
                            print(form.model.email);
                          }
                        : null,
                    child: const Text('Submit'),
                  );
                },
              ),
            ],
          );
        },
      ),
    );
  }
}
vasilich6107 commented 4 months ago

Hey Thanks for finding, check reactive_forms_generator 5.0.3 will add generated popscope class a little bit later

github-actions[bot] commented 1 month ago

Hi @TrplM! Your issue has been closed. If we were helpful don't forget to star the repo.

Please check our reactive_forms_widget package

We would appreciate sponsorship subscription or one time donation https://github.com/sponsors/artflutter