form_bloc
form_bloc copied to clipboard
Form jumps in scroll view
This gif demos how after opening the new route the SingleChildScrollView
scrolls and date field appears at the bottom of the screen
This happens on empty('') values inside
void _fixControllerTextValue(String value) async {
_controller
..text = value ?? ''
..selection = TextSelection.collapsed(offset: _controller.text.length);
// TODO: Find out why the cursor returns to the beginning.
await Future.delayed(Duration(milliseconds: 0));
_controller.selection =
TextSelection.collapsed(offset: _controller.text.length);
}
The root cause is setting the selection offset on empty value if we remove this
..selection = TextSelection.collapsed(offset: _controller.text.length);
// TODO: Find out why the cursor returns to the beginning.
await Future.delayed(Duration(milliseconds: 0));
_controller.selection =
TextSelection.collapsed(offset: _controller.text.length);
On non empty values everything works fins.
As far as _fixControllerTextValue
is used in other methods there could be another workaround
Replace _fixControllerTextValue
with
void _fixControllerTextValue(String value) async {
_controller
..text = value
..selection = TextSelection.collapsed(offset: _controller.text.length);
// TODO: Find out why the cursor returns to the beginning.
await Future.delayed(Duration(milliseconds: 0));
_controller.selection =
TextSelection.collapsed(offset: _controller.text.length);
}
And update the comparison clause
form
if (_controller.text != state.value) {
to
if (_controller.text != (state.value ?? '')) {
This will fix the issue) And reduce the amount of method calls)
there is some kind of a related issue in flutter https://github.com/flutter/flutter/issues/50713
Reproduction https://github.com/flutter/flutter/issues/50713#issuecomment-620098640
@GiancarloCode Hi, do you know any workarounds for this issue?