title: Switching between tabs initstate() called multiple times
body: <p>Switching between tabs initstate() called multiple times.</p>
  
  <p>i have 4 tabs in my tab barA,B,C and D. </p>
  
  <p>case (1) if i switch in tab like from tab A to B it's working fine. </p>
  
  <p>case (2) but if i'm go to tab A to C then initstate() of tab 'B' called two times </p>
  
  <p>results of case (1)</p>
  
  <p>flutter: A</p>
  
  <p>flutter: B</p>
  
  <p>results of case (2)</p>
  
  <p>flutter: A</p>
  
  <p>flutter: B</p>
  
  <p>flutter: C</p>
  
  <p>flutter: B</p>
  
  <pre><code>void main() =&gt; runApp(MyApp());
  
  class MyApp extends StatelessWidget {
    // This widget is the root of your application.
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: MyHomePage(title: 'Flutter Demo Home Page'),
      );
    }
  }
  
  class MyHomePage extends StatefulWidget {
    MyHomePage({Key key, this.title}) : super(key: key);
  
    final String title;
  
    @override
    _MyHomePageState createState() =&gt; _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; with SingleTickerProviderStateMixin{
  
    TabController _controller;
  
    void initState() {
      super.initState();
      _controller = TabController(length: 4, vsync: this);
      _controller.addListener(_handleSelected);
    }
  
    bool alarm = false;
  
  // Function for handle tap event of tab
    void _handleSelected() async {
    }
  
  
    Widget build(BuildContext context) {
      return DefaultTabController(
        length: 4,
        child: Scaffold(
          appBar: AppBar(
            bottom: TabBar(
              controller: _controller,
              tabs: [
                Tab(text: "A"),
                Tab(text: "B"),
                Tab(text: "C"),
                Tab(text: "D"),
              ],
            ),
            actions: [
              Switch(
                value: alarm,
                onChanged: (value) {
                },
                activeTrackColor: Color(0xffff6b6b),
                activeColor: Color(0xffff0000),
              ),
            ],
          ),
          body: TabBarView(
            controller: _controller,
            children: [
              A(),
              B(),
              C(),
              D(),
            ],
          ),
        ),
      );
    }
  }
  </code></pre>