Skip to content

Keep TextFields visible when keyboard comes up - #18291

Merged
goderbauer merged 6 commits into
flutter:masterfrom
goderbauer:textfields
Jun 15, 2018
Merged

goderbauer merged 6 commits into
flutter:masterfrom
goderbauer:textfields

Conversation

@goderbauer

Copy link
Copy Markdown
Member

Fixes #10826.

Also in this PR: If you focus a text field, scroll it out of view and then start typing it will scroll back into view.

_updateOrDisposeSelectionOverlayIfNeeded();
if (!_hasFocus) {
if (_hasFocus) {
// Listen for changing viewInsets, which indicates keyboard showing up.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't something else do that, like rotating the screen, or a "virtual" safe area element (like the iOS bottom button) disappearing? I suppose we probably want this to happen in those cases too, however.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this will be triggered by the events you list as well. I'd argue that you'd still want to ensure that a focused textfield stays visible when any of those happen.

@gspencergoog

Copy link
Copy Markdown
Contributor

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

@goderbauer
goderbauer merged commit 4090078 into flutter:master Jun 15, 2018
@goderbauer
goderbauer deleted the textfields branch June 15, 2018 17:11
srawlins added a commit to srawlins/flutter that referenced this pull request Jun 15, 2018
* master:
  Remove race conditions involving finding available ports (flutter#18488)
  Skip painting hidden children of a sliver list (flutter#18465)
  Fixed some typos (flutter#18516)
  update Tristate checkbox semantics to consider indeterminate as "unchecked" (flutter#18297)
  Add flutter tool support for creating app-specific VM snapshots. (flutter#18417)
  mention Text.rich on RichText (flutter#18434)
  invert children for real (flutter#18489)
  Fix clipping for SliverLists (flutter#18410)
  Keep TextFields visible when keyboard comes up (flutter#18291)
  Update all packages (flutter#18506)
  Prepare for upgrading video player in Gallery to newest version (flutter#18501)
  Update Android dependencies (flutter#18499)
  Enable running with prebuilt test-only apk (flutter#18453)
  Revert "Update all packages (flutter#18471)" (flutter#18492)
  Add some more dart doc to RepaintBoundary (flutter#17183)
  Update all packages (flutter#18471)
  Clean up output of "flutter run --release" (flutter#18380)
  Ensure errors launching emulators are exposed to the daemon (flutter#18446)
  Check video widget is mounted on call to setState (flutter#18467)
  Fixed concurrent list modification in vmservice.dart
@zoechi

zoechi commented Jun 27, 2018

Copy link
Copy Markdown
Contributor

@Aklil are you creating the TextEditingController for this input field inside the build() {...} method?
Is your input inside a ListView or another scrollable?

@Aklil

Aklil commented Jun 27, 2018 •

Copy link
Copy Markdown

@zoechi yes I've them in a listview. Depending on the data I receive from an API, I build the input fields with TextEditingControllers.

//field  
final List<TextEditingController> _textEditingControllers = [];

//in build method the controllers are populated
 this._textEditingControllers.add(TextEditingController());

//then when each text input field is created, the controller is assigned as follows
TextFormField(
          controller: this._textEditingControllers[index],
          keyboardType: TextInputType.number,

@zoechi

zoechi commented Jun 27, 2018

Copy link
Copy Markdown
Contributor

final List<TextEditingController> _textEditingControllers = []; seems redundant because you don't use it in the other code.
this._textEditingControllers.add(TextEditingController()); means that the TextEditingController is recreated every time the tree is rebuilt.

@Aklil

Aklil commented Jun 27, 2018 •

Copy link
Copy Markdown

@zoechi I have created the controllers in the initState() method. but still experiencing the same issue. Even tried to populate them in the constructor of the state class.

@Aklil

Aklil commented Jun 27, 2018 •

Copy link
Copy Markdown

@zoechi Creating the global form key outside of the build method has resolved my issue. But I wanted to know whether it is a normal situation for the tree to be re-rendered when the text field is being focused and up on keyboard enter in the input. Thanks for your help.

@goderbauer goderbauer added framework flutter/packages/flutter repository. See also f: labels. f: scrolling Viewports, list views, slivers, etc. labels Feb 22, 2019
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scroll text fields into view when keyboard comes up and obscures them

5 participants