form_bloc icon indicating copy to clipboard operation
form_bloc copied to clipboard

Form jumps in scroll view

Open vasilich6107 opened this issue 4 years ago • 3 comments

This gif demos how after opening the new route the SingleChildScrollView scrolls and date field appears at the bottom of the screen

ezgif com-video-to-gif

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)

vasilich6107 avatar Apr 27 '20 13:04 vasilich6107

there is some kind of a related issue in flutter https://github.com/flutter/flutter/issues/50713

vasilich6107 avatar Apr 27 '20 13:04 vasilich6107

Reproduction https://github.com/flutter/flutter/issues/50713#issuecomment-620098640

vasilich6107 avatar Apr 27 '20 16:04 vasilich6107

@GiancarloCode Hi, do you know any workarounds for this issue?

vasilich6107 avatar Jul 06 '20 10:07 vasilich6107