title: Flutter - ListView inside on a TabBarView loses its scroll position
body: <p>I have a very simple Flutter app with a <strong>TabBarView</strong> with two views (<strong>Tab 1</strong> and <strong>Tab 2</strong>), one of them (<strong>Tab 1</strong>) has a ListView with many simple Text Widgets, the problem with this is that after I scroll down the ListView elements of <strong>Tab 1</strong>, if I swipe from <strong>Tab 1</strong> to <strong>Tab 2</strong> and finally I swipe from
  <strong>Tab 2</strong> to <strong>Tab 1</strong>, the previous scroll position in the ListView of <strong>Tab 1</strong> get lost.</p>
  <p>Here is the code:</p>
  <pre><code>import 'package:flutter/material.dart';
  
  void main() {
    runApp(MyApp());
  }
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const MyHomePage(title: 'Flutter Demo Home Page'),
      );
    }
  }
  
  class MyHomePage extends StatefulWidget {
    const MyHomePage({Key? key, required this.title}) : super(key: key);
  
    final String title;
  
    @override
    _MyHomePageState createState() =&gt; _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt;
      with SingleTickerProviderStateMixin {
    late TabController controller;
  
    @override
    void initState() {
      super.initState();
      controller = TabController(
        length: 2,
        vsync: this,
      );
    }
  
    @override
    void dispose() {
      controller.dispose();
      super.dispose();
    }
  
    @override
    Widget build(BuildContext context) {
      var tabs = const &lt;Tab&gt;[
        Tab(icon: Icon(Icons.home), text: 'Tab 1'),
        Tab(icon: Icon(Icons.account_box), text: 'Tab 2')
      ];
  
      return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: TabBarView(controller: controller, children: &lt;Widget&gt;[
          ListView(children: &lt;Widget&gt;[
            Column(children: &lt;Widget&gt;[
              for (int i = 0; i &lt; 48; i++) Text('Data $i'),
            ])
          ]),
          const Center(child: Text('Tab 2'))
        ]),
        bottomNavigationBar: Material(
          color: Colors.deepOrange,
          child: TabBar(controller: controller, tabs: tabs),
        ),
      );
    }
  }
  </code></pre>
  <p>I have even separated the <strong>TabBarView</strong> <strong>childrens</strong> (Tab 1 and Tab 2) in another classes and I have noticed that the</p>
  <pre><code>@override
    Widget build(BuildContext context) {
    ...
  }
  </code></pre>
  <p>method of each child (Tab 1 and Tab 2) is executed every time I swipe to its container tab.</p>
  <p>My questions are:</p>
  <p><strong>1.- How can I keep the scroll of the <em>ListView</em> even if I move from tab to tab?</strong></p>
  <p><strong>2.- Is there a way to execute the</strong></p>
  <pre><code>@override
  Widget build(BuildContext context) {
  
  }
  </code></pre>
  <p><strong>method only once if I separate the <em>TabBarView childrens</em> (Tab 1 and Tab 2) to another classes?</strong>
  I mean, if I have to retrieve data when the Tab 1 and Tab 2 are created I don't want to do this every time its Tab is swiped in. That would be expensive.</p>
  <p><strong>3.- In general, Is there a way to prevent that a tab view (including its variables, data, etc.) be rebuilt every time I swipe to that tab?</strong></p>
  <p><strong>Thank you in advance.</strong></p>