简体   繁体   中英

how to avoid scrolling to the TEXTFORMFIELD when I force input value to that field in flutter

I have two text form fields that change same value on the same screen in flutter (to make it easier on the user), the user can change the variable from any of the two fields.

The problem is that when the user changes the value in one field (and while still inputting) flutter automatically scrolls to the second field, and even worse the animation is unpredictable sometimes it scrolls back to the original field and sometimes it keeps the view to the second field.

What I need is to make flutter ignore this animation. I want the user to change the value of the text field as a normal iput and in the background flutter would change the second field, so that is the use of scroll down at some point to the second field he will find the variable updated.

CustomTextFormFieldRow(
                        maxLength: 5,
                        suffixText: 'in',
                        labelText: 'Annular Diam.',
                        maxInput: kMaxHoleSize,
                        minInput: _casing.iDiameter(),
                        controller: _controller1,
                        onChanged: (value) {
                          if (value.isNotEmpty &&
                              value != '.' &&
                              double.tryParse(value) != null) {
                            _annularOD = double.tryParse(value);
                            _controller2.text = value;
                          } else {
                            _annularOD = 0;
                          }
                          setState(() {
                            _annularOD;
                          });
                        },
                      ),

Here I have a custom form field that I have created, I have created two of those on my screen each having its own controller named one and two, when the user input value add any of them I setState() and change the value of the other controller with _controller2.text = value;

check your controller looks like you have provided the same controller to both text form field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM