title: Passing data between pages with bottom navigation bar in flutter
body: <p>I have an app that routes to a "mainapp" page after logging in. This app contains a bottom navigation bar which displays pages of the corresponding pressed icon. I want to pass data of type <code>Map&lt;String, dynamic&gt;</code> to these pages but I am having trouble. This map is generated from a function that fetches the data from a server, saves it to shared preferences, then loads the shared preferences and returns it as a map (all contained in <code>getData()</code>). I want to pass this map around so I don't have to load shared preferences each time, but will also update this map along with shared preferences when needed( possibly an action on one of the pages). </p>
  
  <pre><code>class MainApp extends StatefulWidget {
    @override
    _MainAppState createState() =&gt; _MainAppState();
  }
  
  class _MainAppState extends State&lt;MainApp&gt; {
  
  
    Map&lt;String, dynamic&gt; Data;
  
  
    StartFunc() async {
     Data = await getData();
     setState(() {}); 
   }
  
  
    @override
    void initState() {
      StartFunc();
      super.initState();
    }
  
    var _pages = [
      PageOne(Data:Data),
      PageTwo(),
      PageThree(),
     PageFour(),
     PageFive(),
    ];
  
    int _currentIndex = 0;
  
    onTabTapped(int index) {
      setState(() {
        _currentIndex = index;
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return _currentIndex == 2
          ? PageTwo()
          : Scaffold(
        body: _pages[_currentIndex],
        bottomNavigationBar: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          items: [
            BottomNavigationBarItem(
                icon: Icon(Icons.library_books), title: Text('')),
            BottomNavigationBarItem(
                icon: Icon(Icons.notifications), title: Text('')),
            BottomNavigationBarItem(
                icon: Icon(Icons.add_circle_outline), title: Text('')),
            BottomNavigationBarItem(
                icon: Icon(Icons.mail), title: Text('')),
            BottomNavigationBarItem(
                icon: Icon(Icons.person), title: Text('')),
          ],
          onTap: onTabTapped,
          currentIndex: _currentIndex,
        ),
      );
    }
  }
  </code></pre>
  
  <p>I'm getting an error saying <strong>Only static members can be accessed in initializers</strong>. I was wondering if inherited widgets or other design patterns such as scoped model and BLoC can help but not sure if that's the right way to go. I'm also not sure how I would start implementing them in this case. </p>