title: How to preserve widget states in flutter, when navigating using BottomNavigationBar?
body: <p>I'm currently working on building a Flutter app that will preserve states when navigating from one screen, to another, and back again when utilizing <a href="https://docs.flutter.io/flutter/material/BottomNavigationBar-class.html" rel="noreferrer">BottomNavigationBar</a>. Just like it works in the Spotify mobile application; if you have navigated down to a certain level in the navigation hierarchy on one of the main screens, changing screen via the bottom navigation bar, and later changing back to the old screen, will preserve where the user were in that hierarchy, including preservation of the state.</p>
  
  <p>I have run my head against the wall, trying various different things without success.</p>
  
  <p>I want to know how I can prevent the pages in <code>pageChooser()</code>, when toggled once the user taps the BottomNavigationBar item, from rebuilding themselves, and instead preserve the state they already found themselves in (the pages are all stateful Widgets).</p>
  
  <pre><code>import 'package:flutter/material.dart';
  import './page_plan.dart';
  import './page_profile.dart';
  import './page_startup_namer.dart';
  
  void main() =&gt; runApp(new Recipher());
  
  class Recipher extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return new Pages();
    }
  }
  
  class Pages extends StatefulWidget {
    @override
    createState() =&gt; new PagesState();
  }
  
  class PagesState extends State&lt;Pages&gt; {
    int pageIndex = 0;
  
  
    pageChooser() {
      switch (this.pageIndex) {
        case 0:
          return new ProfilePage();
          break;
  
        case 1:
          return new PlanPage();
          break;
  
        case 2:
          return new StartUpNamerPage(); 
          break;  
  
        default:
          return new Container(
            child: new Center(
              child: new Text(
                'No page found by page chooser.',
                style: new TextStyle(fontSize: 30.0)
                )
              ),
            );     
      }
    }
  
    @override
    Widget build(BuildContext context) {
      return new MaterialApp(
        home: new Scaffold(
          body: pageChooser(),
          bottomNavigationBar: new BottomNavigationBar(
            currentIndex: pageIndex,
            onTap: (int tappedIndex) { //Toggle pageChooser and rebuild state with the index that was tapped in bottom navbar
              setState(
                (){ this.pageIndex = tappedIndex; }
                ); 
              },
            items: &lt;BottomNavigationBarItem&gt;[
              new BottomNavigationBarItem(
                title: new Text('Profile'),
                icon: new Icon(Icons.account_box)
                ),
                new BottomNavigationBarItem(
                  title: new Text('Plan'),
                  icon: new Icon(Icons.calendar_today)
                ),
                  new BottomNavigationBarItem(
                  title: new Text('Startup'),
                  icon: new Icon(Icons.alarm_on)
                )
              ],
            )
        )
      );
    }
  }
  </code></pre>