reactive_forms icon indicating copy to clipboard operation
reactive_forms copied to clipboard

Strange scroll after updateAndValidity

Open piuskamil opened this issue 3 years ago • 9 comments

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.

piuskamil avatar Mar 29 '21 15:03 piuskamil

This is probably a focus issue due to a rebuild.

kuhnroyal avatar Mar 29 '21 15:03 kuhnroyal

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

piuskamil avatar Mar 29 '21 15:03 piuskamil

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.

kuhnroyal avatar Mar 29 '21 16:03 kuhnroyal

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

FocusScope.of(context).unfocus();

Or maybe unfocus control after updateAndValidity.

piuskamil avatar Mar 29 '21 16:03 piuskamil

I have tried everything. No luck yet

piuskamil avatar Mar 30 '21 12:03 piuskamil

@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 avatar Apr 06 '21 17:04 vasilich6107

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 avatar Apr 06 '21 17:04 vasilich6107

@piuskamil did you succeed in fixing the issue?

vasilich6107 avatar Jul 12 '21 20:07 vasilich6107

@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

piuskamil avatar Jul 13 '21 04:07 piuskamil