joanpablo / reactive_forms

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

Strange scroll after updateAndValidity #130

Open piuskamil opened 3 years ago

piuskamil commented 3 years ago

Hi. I'm not sure it's directly connected with reactive_forms plugin. In my case I have very complicated, nested (3 level) form with multiple listeners to show hide controls and custom validators. And it's generated from json configuration. It was easy to rewrite my angular implementation to flutter, thank you for that plugin :) But there is strange behavior. After I select a radio button and manually do updateAndValidity on other form control which validation depends on that radio button then suddenly my screen scrolls to that field. And it's happens only once at first updateAndValidity. If i set emitEvent on false then scroll not change but my validation message is not visible. I'm not sure what is happening.

kuhnroyal commented 3 years ago

This is probably a focus issue due to a rebuild.

piuskamil commented 3 years ago

I'm sure I don't have focus on that field. Or do u mean updateAndValidity set focus on that field somehow ?

kuhnroyal commented 3 years ago

Or do u mean updateAndValidity set focus on that field somehow ?

No, not intentionally, but it causes a rebuild of the widget and that might focus the next untouched field or something.

piuskamil commented 3 years ago

Ok maybe. I will try some kind of unfocus thing. Like

FocusScope.of(context).unfocus();

Or maybe unfocus control after updateAndValidity.

piuskamil commented 3 years ago

I have tried everything. No luck yet

vasilich6107 commented 3 years ago

@piuskamil there is a corresponding flutter issue for such behaviour https://github.com/flutter/flutter/issues/50713#issuecomment-620098640

I didn't check if it realy fixed.

Here is my reproduction repo https://github.com/artflutter/flutter_issue_50713

vasilich6107 commented 3 years ago

I've just tried my own repo)

This fix does not present in 2.0.4 But present in 2.1.0-13.0.pre.479

vasilich6107 commented 3 years ago

@piuskamil did you succeed in fixing the issue?

piuskamil commented 3 years ago

@vasilich6107 partly, I have used listview builder to split my form and lazy load hidden parts of the form and this issue no longer occurs