title: How to use shared preferences to read data for all bottom tabs screen in flutter
body: <p>I need to save my data and then read it in all tabs and I try to save and read my data using shared preferences. Right now I have 3 screens, they are login, home, and profile screen. Inside home and profile, I use bottom tab navigator, so after users login (post their data and I save that data using shared preferences and I want to access that data in home and profile screen). What I make confused is... after I click login button, I navigate it to BottomTab file where ButtomTab file consist of home and profile screen and I get confused how to read my data in home and profile screen using shared preferences because after login, I navigate it to my BottomTab, not my Home Screen. Here is my code
  main.dart</p>
  
  <pre><code>void main() =&gt; runApp(MyApp());
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        home: LoginScreen(),
      );
    }
  }
  </code></pre>
  
  <p>my Login Screen</p>
  
  <pre><code>class _LoginScreenState extends State&lt;LoginScreen&gt; {
  postData() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.setInt('username', _username.text);
    Navigator.push(context,
                new MaterialPageRoute(
                    builder: (BuildContext context) =&gt;
                        new BottomTab()));
  }
  @override
    Widget build(BuildContext context) {
      return Column(
               children:&lt;Widget&gt;[
                 TextFormField(
                   controller: _username),
                 FlatButton(
                   child: Text("Login"),
                   onPressed: () {
                      postData(_username.text);}),];}
  }
  </code></pre>
  
  <p>my BottomTab file</p>
  
  <pre><code>class _BottomTab extends State&lt;BottomTab&gt; {
  
    int _selectedIndex = 0;
  
    _onTap(int index) {
      setState(() =&gt; _myindex = index);
    }
  
    final List&lt;Widget&gt; pages = [
      HomeScreen(),
      ProfileScreen(), 
    ];
  
    final PageStorageBucket bucket = PageStorageBucket();
  
    Widget _myNavigation(int selectedIndex) =&gt; BottomNavigationBar(
          onTap: _onTap,
          currentIndex: myindex,
          type: BottomNavigationBarType.fixed,
          items: const &lt;MyTab&gt;[
            MyTab(icon: Icon(Icons.home), title: Text('Home')),
            MyTab(icon: Icon(Icons.person), title: Text('Profile')),
          ],
        );
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        bottomNavigationBar: _myNavigation(_myindex),
        body: PageStorage(
          child: pages[_myindex],
          bucket: bucket,
        ),
      );
    }
  }
  </code></pre>
  
  <p>my Home Screen</p>
  
  <pre><code>class _HomeScreen extends State&lt;HomeScreen&gt; {
  @override
    Widget build(BuildContext context) {
  
      return Container(
        child: Text("Hello ${...username that I want to pass}"),
      );
    }
  }
  
  </code></pre>