title: Shared Preferences doesn't work with Bottom Navigation Bar
body: <p>I have faced an issue on getting data from Shared Preferences. It works anywhere except for win_loss.dart.</p>
  <p>Below is the page pulled up right after user signs in. win_loss is pulled up as a part of home_page.dart (default page of bottom navigation bar). Shared preferences data can't be pulled and assigned to userInfo[] when home_page.dart is viewed. I tried Futurebuilder, which doesn't work.</p>
  <p>Please help me :)</p>
  <p>Thanks,</p>
  <p>============ home_page.dart ==================</p>
  <pre><code>import 'package:cloud_firestore/cloud_firestore.dart';
  import 'package:firebase_auth/firebase_auth.dart';
  import 'package:flutter/material.dart';
  import 'package:google_sign_in/google_sign_in.dart';
  import 'package:shared_preferences/shared_preferences.dart';
  import 'package:Config/design_Config.dart';
  import 'package:CustomWidgetMethod/custom_ListTile.dart';
  import 'package:club_Info.dart';
  import 'package:ranking.dart';
  import 'package:win_Loss.dart';
  
  class HomePage extends StatefulWidget {
    @override
    State&lt;HomePage&gt; createState() =&gt; _HomePageState();
  }
  
  class _HomePageState extends State&lt;HomePage&gt; {
    // Sign with Google
    final GoogleSignIn _googleSignIn = GoogleSignIn();
  
    // User Info Variables
    String _userUid = '';
    String _userName = '';
    String _userEmail = '';
    String _userMemberLevel = '';
    List&lt;String&gt; _userClub = [];
    String _userTennisLevel = '';
    int _userTotalMatchPerDay = 0;
    int _userBirthYear = 0;
    int _userBirthMonth = 0;
    int _userBirthDay = 0;
  
    @override
    void initState() {
      super.initState();
      _userInfo(FirebaseAuth.instance.currentUser!.uid)
          .then((_) =&gt; _getUserInfoToSharedPreferences());
    }
  
    // Shared Preference
    final Future&lt;SharedPreferences&gt; _sharedPrefs =
        SharedPreferences.getInstance();
  
    //Bottom Navigation Bar
    int selectedIndex = 1;
    List&lt;Widget&gt; navigationBarItems = [ClubInfo(), WinLoss(), Ranking()].toList();
  
    void onTap(int index) {
      setState(() {
        selectedIndex = index;
      });
    }
  
    // SignOut
    Future&lt;void&gt; _signOut() async {
      await FirebaseAuth.instance.signOut();
      await _googleSignIn.signOut();
      await _googleSignIn.disconnect();
  
      final SharedPreferences sharedPrefs = await _sharedPrefs;
  
      await sharedPrefs.remove('userUid');
      await sharedPrefs.remove('userName');
      await sharedPrefs.remove('userEmail');
      await sharedPrefs.remove('userMemberLevel');
      await sharedPrefs.remove('userClub');
      await sharedPrefs.remove('userTennisLevel');
      await sharedPrefs.remove('userTotalMatchPerDay');
      await sharedPrefs.remove('userBirthYear');
      await sharedPrefs.remove('userBirthMonth');
      await sharedPrefs.remove('userBirthday');
    }
  
    // Get and Save User Info to Shared Preference
    Future&lt;void&gt; _userInfo(String userUid) async {
      print('aha');
      DocumentSnapshot snapshot =
          await FirebaseFirestore.instance.collection('users').doc(userUid).get();
      if (snapshot.exists) {
        Map&lt;String, dynamic&gt;? userInfo = snapshot.data() as Map&lt;String, dynamic&gt;?;
  
        //Generating SharedPreference Instance.
        final SharedPreferences sharedPrefs = await _sharedPrefs;
        await sharedPrefs.setString('userUid', userInfo?['userUid']);
        await sharedPrefs.setString('userName', userInfo?['userName']);
        await sharedPrefs.setString('userEmail', userInfo?['userEmail']);
        await sharedPrefs.setString(
            'userMemberLevel', userInfo?['userMemberLevel']);
        List&lt;String&gt; _userClubList = [];
        userInfo?['userClub'].forEach((clubInfo) {
          print(clubInfo);
          _userClubList.add(clubInfo);
          print('_UserclubList: $_userClubList');
        });
        await sharedPrefs.setStringList('userClub', _userClubList);
        await sharedPrefs.setString(
            'userTennisLevel', userInfo?['userTennisLevel']);
        await sharedPrefs.setInt(
            'userTotalMatchPerDay', userInfo?['userTotalMatchPerDay']);
        await sharedPrefs.setInt('userBirthYear', userInfo?['userBirthYear']);
        await sharedPrefs.setInt('userBirthMonth', userInfo?['userBirthMonth']);
        await sharedPrefs.setInt('userBirthday', userInfo?['userBirthday']);
      }
    }
  
    // Get User Info From Shared Preferences.
    _getUserInfoToSharedPreferences() async {
      SharedPreferences _sharedPrefs = await SharedPreferences.getInstance();
      setState(() {
        _userUid = _sharedPrefs.getString('userUid') ?? '';
        _userName = _sharedPrefs.getString('userName') ?? '';
        _userEmail = _sharedPrefs.getString('userEmail') ?? '';
        _userMemberLevel = _sharedPrefs.getString('userMemberLevel') ?? '';
        _userClub = _sharedPrefs.getStringList('userClub') ?? [];
        _userTennisLevel = _sharedPrefs.getString('userTennisLevel') ?? '1.0';
        _userTotalMatchPerDay = _sharedPrefs.getInt('userTotalMatchPerDay') ?? 0;
        _userBirthYear = _sharedPrefs.getInt('userBirthYear') ?? 0;
        _userBirthMonth = _sharedPrefs.getInt('userBirthMonth') ?? 0;
        _userBirthDay = _sharedPrefs.getInt('userBirthMonth') ?? 0;
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return WillPopScope(
        onWillPop: () async =&gt; false,
        child: Scaffold(
          appBar: AppBar(
            title: Text(
              _userEmail,
              // _userClub.isNotEmpty ? _userClub.first : '가입 클럽 없음',
              style: const TextStyle(fontSize: DesignConfig.appBarFontSize),
            ),
  
          ),
          bottomNavigationBar: BottomNavigationBar(
            backgroundColor: Colors.blue,
            onTap: onTap,
            currentIndex: selectedIndex,
            type: BottomNavigationBarType.fixed,
            selectedFontSize: 50,
            unselectedFontSize: 20,
            selectedItemColor: Colors.white,
            selectedIconTheme: const IconThemeData(color: Colors.white, size: 25),
            unselectedIconTheme:
                const IconThemeData(color: Colors.black, size: 22),
            selectedLabelStyle: const TextStyle(
                color: Colors.white, fontSize: 15, fontWeight: FontWeight.bold),
            unselectedLabelStyle: const TextStyle(
                color: Colors.black, fontSize: 10, fontWeight: FontWeight.bold),
            items: const [
              BottomNavigationBarItem(
                icon: Icon(Icons.cabin),
                label: &quot;Info&quot;,
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.battery_unknown),
                label: &quot;Win or Lost&quot;,
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.list_alt),
                label: &quot;Ranking&quot;,
              ),
            ],
          ),
          body: navigationBarItems[selectedIndex],
        ),
      );
    }
  }
  </code></pre>
  <p>============ win_loss.dart ==================</p>
  <pre><code>import 'package:cloud_firestore/cloud_firestore.dart';
  import 'package:flutter/material.dart';
  import 'package:intl/intl.dart';
  import 'package:shared_preferences/shared_preferences.dart';
  import 'package:Config/design_Config.dart';
  import 'package:CustomWidgetMethod/custom_CircularProgressIndicator.dart';
  import 'package:CustomWidgetMethod/custom_SnackBar.dart';
  
  class WinLoss extends StatefulWidget {
    @override
    State&lt;WinLoss&gt; createState() =&gt; _WinLossState();
  }
  
  class _WinLossState extends State&lt;WinLoss&gt; {
  
    // User Info Variables
    String _userUid = '';
    String _userName = '';
    String _userEmail = '';
    String _userMemberLevel = '';
    List&lt;String&gt; _userClub = [];
    String _userTennisLevel = '';
    int _userTotalMatchPerDay = 0;
    int _userBirthYear = 0;
    int _userBirthMonth = 0;
    int _userBirthDay = 0;
  
  
    // Max Match Per Day
    int _maxMatchPerDay = 3;
  
    // Scoring
    int _matchScore = 0;
    int _gameScore = 0;
  
    final Color _selectedColor = Colors.blue;
    final Color _unselectedColor = Colors.grey;
  
    // Get Current Time
    DateTime now = DateTime.now();
    String formattedDate =
    DateFormat('yyyy').format(DateTime.now());
  
    // User Info Variables
    List&lt;dynamic&gt; userInfo = [];
  
  
    @override
    void initState() {
      super.initState();
      SharedPreferences.getInstance().then((SharedPreferences _sharedPref) =&gt;
          _getUserInfoToSharedPreferences(_sharedPref));
    }
  
  
    // Get User Info From Shared Preferences.
    Future&lt;List&lt;dynamic&gt;&gt; _getUserInfoToSharedPreferences(
        SharedPreferences sharedPref) async {
      userInfo.add(sharedPref.getString('userUid') ?? '');
      userInfo.add(sharedPref.getString('userName') ?? '');
      userInfo.add(sharedPref.getString('userEmail') ?? '');
      userInfo.add(sharedPref.getString('userMemberLevel') ?? '');
      userInfo.add(sharedPref.getStringList('userClub') ?? []);
      userInfo.add(sharedPref.getString('userTennisLevel') ?? '1.0');
      userInfo.add(sharedPref.getInt('userTotalMatchPerDay') ?? 0);
      userInfo.add(sharedPref.getInt('userBirthYear') ?? 0);
      userInfo.add(sharedPref.getInt('userBirthMonth') ?? 0);
      userInfo.add(sharedPref.getInt('userBirthMonth') ?? 0);
      return userInfo;
    }
  
    Future&lt;int?&gt; _updateScore() async {
      setState(() {
        // The first &quot;FormattedDate&quot; was inintiled
        formattedDate =
            DateFormat('yyyy년 MM월 dd일 kk시 mm분').format(DateTime.now());
        print('New FormattedDAte: $formattedDate');
      });
  
      print(userInfo[0]);
      print(userInfo[1]);
      print(userInfo[2]);
      print(userInfo[3]);
      print(userInfo[4][0]);
  
      DocumentReference docRef = FirebaseFirestore.instance
          .collection('clubs')
          .doc(userInfo[4][0])
          .collection('matches')
          .doc('match')
          .collection('individuals')
          .doc(userInfo[2]);
  
      return await docRef.get().then((DocumentSnapshot documentSnapshot) async {
        if (!documentSnapshot.exists) {
          print('Docs: ${documentSnapshot.exists}');
  
          int _userTotalMatchPerDay = 1;
          print('No Data1');
          await docRef
              .set({
            'userUid': userInfo[0],
            'userName': userInfo[1],
            'userEmail': userInfo[2],
            'timeEnter': formattedDate,
            'userTotalMatchPerDay': 1,
            'accumulatedMatchScore': _matchScore,
            'accumulatedGameScore': _gameScore,
          })
              .then((value) =&gt; print('Success'))
              .catchError((error) =&gt; print(&quot;Failed to update user: $error&quot;));
  
          print('No Data2');
          await docRef
              .collection('scores')
              .doc(formattedDate)
              .set({
            'userUid': userInfo[0],
            'userName': userInfo[1],
            'userEmail': userInfo[2],
            'timeEnter': formattedDate,
            'matchScore': _matchScore,
            'gameScore': _gameScore,
          })
              .then((value) =&gt; print('Success'))
              .catchError((error) =&gt; print(&quot;Failed to update user: $error&quot;));
  
          print('No Data3');
          print(_userTotalMatchPerDay);
          return _userTotalMatchPerDay;
        } else {
          print('No Data4');
          // int newFollowerCount = snapshot.data()['followers'] + 1;
          // Count Up Match # Per Day
          int _userTotalMatchPerDay =
              documentSnapshot['userTotalMatchPerDay'] + 1;
          // Check Reach the Day Limit
          if (_userTotalMatchPerDay &lt; _maxMatchPerDay + 1) {
            print('test 2');
            // Update Total Doc
            docRef.update({'userTotalMatchPerDay': _userTotalMatchPerDay});
  
            // If Win (1) comes run this below. If not (0), don't run it
            if (_matchScore == 1) {
              print('test 3');
              int accumulatedMatchScore =
                  documentSnapshot['accumulatedMatchScore'] + _matchScore;
              docRef
                  .update({'accumulatedMatchScore': accumulatedMatchScore})
                  .then((value) =&gt; print('Success'))
                  .catchError((error) =&gt; print(&quot;Failed to update user: $error&quot;));
            }
            // Update # of Game won
            int accumulatedGameScore =
                documentSnapshot['accumulatedGameScore'] + _gameScore;
            docRef
                .update({'accumulatedGameScore': accumulatedGameScore})
                .then((value) =&gt; print('Success'))
                .catchError((error) =&gt; print(&quot;Failed to update user: $error&quot;));
  
            print('No Data5');
            await docRef
                .collection('scores')
                .doc(formattedDate)
                .set({
              'userUid': userInfo[0],
              'userName': userInfo[1],
              'userEmail': userInfo[2],
              'timeEnter': formattedDate,
              'matchScore': _matchScore,
              'gameScore': _gameScore,
            })
                .then((value) =&gt; print('Success'))
                .catchError((error) =&gt; print(&quot;Failed to update user: $error&quot;));
  
            print('No Data6');
          }
          print(_userTotalMatchPerDay);
          return _userTotalMatchPerDay;
        }
      }).then((userTotalMatchPerDay) async {
        print('userTotalMatchPerDay: $userTotalMatchPerDay');
        print('formattedDate: $formattedDate');
        if ((userTotalMatchPerDay) &gt; 3) {
          return userTotalMatchPerDay;
        }
      });
      return null;
    }
  
    @override
    Widget build(BuildContext context) {
      return Center(
        child: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.symmetric(horizontal: DesignConfig.padding),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                const Text(
                  &quot;Match&quot;,
                  style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
                ),
              ],
            ),
          ),
        ),
      );
    }
  }
  </code></pre>