Search code examples
flutterflutter-layout

Tab navigation selection reverts to first one when text field is used in other tabs


I have a bottom tab bar with each tab associated with a screen (basically a Scaffold). The tab that contains the TextField has a ListView. When I am in that tab and click on the TextInputField. Native keyboard pops up and when I am done, the keyboard disappears leaving me with the same tab view but the selection of the tab is now changed to the first tab.

What I figured we need to replicate the above: • Tab navigation • Have an input field in a tab other than the first one.

enter image description here

Happy to provide any further details. Thank you.


Solution

  • Fixed it. The problem was that I was initializing the controller inside the build method and so the controller got initialized with initial index zero every time the build method was called. Initializing in the initState solved it.