artflutter / reactive_forms_generator

Other
89 stars 22 forks source link

Add ability to manage form lifecycle manually (#149) #150

Closed BenjiFarquhar closed 4 months ago

BenjiFarquhar commented 7 months ago

If you want to manage the form lifecycle manually, you can now pass formModel instead of model into the FormBuilder widget. The behaviour remains the same when passing in model.

The required check for model:

..required = !reactiveForm.reactiveInheritedStreamer
                      .formGenerator.element.isNullable

needed to be moved to initState, because it is now possible to pass in formModel, meaning model would no longer be required even if _element.isNullable is false.

Also fixed the order of super calls.

vasilich6107 commented 7 months ago

hi it will be better to create separate ...FormModelBuilder for those cases. widgets that are mixing 2 approaches in one - not the most flexible solution This comes obvious if we check the code

this are two code smells that signify the need to split

if (widget.model != null && widget.formModel != null) {
      throw ArgumentError('Cannot provide both model and formModel.');
    }
if (widget.formModel != oldWidget.formModel) {
      if (widget.formModel == null) {
        throw ArgumentError('formModel must not be set to null');
      }

      _formModel = widget.formModel!;
    }
BenjiFarquhar commented 7 months ago

@vasilich6107 That should be fine; I can look into doing that, but it probably won't be super soon. What are those code smells? Is it because the consumer of the package might use it incorrectly?

Edit: I'm pretty sure the second code block will be necessary even when split into another widget? Oh, or just make it required non-nullable...I see

vasilich6107 commented 7 months ago

@BenjiFarquhar First and most important - we use one widget for 2 purposes. We have to additionally check incoming operators. We have to act differently in did update widget and init state. In case if there are more changes required we will have to modify the widget more and more(in case if we have separate widgets we just need to fix only the necessary prart)

Probably I could help you with splitting. may be later this month