slovnicki / contained_tab_bar_view

Encapsulate TabController, TabBar and TabBarView into a single customizable Widget
MIT License
18 stars 12 forks source link

On tab change content from textformfield has lost #33

Open jeffersonmello opened 2 years ago

jeffersonmello commented 2 years ago

image image image

devj3ns commented 2 years ago

Hey @jeffersonmello, if your TextFields or TextFormFields are connected to a TextEditingController than the state should be preserved.

Here is an example which worked for me:

class ExampleWithTextField extends StatelessWidget {
  final controller1 = TextEditingController();
  final controller2 = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Example 3'),
      ),
      body: ContainedTabBarView(
        tabs: [
          Text('First'),
          Text('Second'),
        ],
        views: [
          Container(
            child: TextField(
              controller: controller1,
            ),
          ),
          Container(
            child: TextField(
              controller: controller2,
            ),
          ),
        ],
      ),
    );
  }
}

I hope this helps, if not, please provide more information and your code :)