title: Why get data from shared preferences have a delayed?
body: <p>I have one screen to display data from shared preferences. I already success save and get data from shared preferences. Then I have a flow in one screen like this:</p>
  
  <ol>
  <li>If the user clicks that screen, it will check the data from shared preferences.</li>
  <li>If data is not null / not empty, it will display the data login like user profile, etc.</li>
  <li>If data is null/empty, it will show a button login.</li>
  </ol>
  
  <p>I get the logic for that flow, but the problem is, before data showing in the screen (number 2), it shows button login first for a few milliseconds then show the data. Why did it happen? It's not got data from API / internet and I'm not using FutureBuilder, I just using Shared Preferences. How to kill this delayed? Below is my full code:</p>
  
  <pre><code>class MorePage extends StatefulWidget {
    @override
    _MorePageState createState() =&gt; _MorePageState();
  }
  
  class _MorePageState extends State&lt;MorePage&gt; {
  
    bool isLoading = false;
    SessionManager _sessionManager = SessionManager();
    int status;
  
    @override
    void initState() {
      super.initState();
      _sessionManager.getStatusLogin().then((value) { //i use this for get status code login success
        setState(() {
          status = value;
        });
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        backgroundColor: color_grey_bg,
        body: SafeArea(
          child: getMorePage(),
        ),
      );
    }
  
    Widget getMorePage() {
      return ListView(
        physics: ClampingScrollPhysics(),
        children: &lt;Widget&gt;[
          Container(
            padding: EdgeInsets.only(
              left: MediaQuery.of(context).size.width / 20,
            ),
            height: MediaQuery.of(context).size.width / 4,
            width: MediaQuery.of(context).size.width,
            color: color_white,
            child: setProfile(),
          ),
        ],
      );
    }
  
    Widget setProfile() {
      if (status == 200) { // i use this logic to show widget with status login, but it's have delayed like show data from API. How to kill it? Because I using SharedPreferences, not hit the API
        return profileUser();
      } else {
        return notSignIn();
      }
    }
  
    Widget profileUser() {
      return Row(
        children: &lt;Widget&gt;[
          Column(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: &lt;Widget&gt;[
              Text(
                name,
                style: TextStyle(
                  color: color_grey_text,
                  fontSize: MediaQuery.of(context).size.width / 26,
                  fontWeight: FontWeight.bold,
                ),
              ),
              Text(
                email,
                style: TextStyle(
                  color: color_grey_text,
                  fontSize: MediaQuery.of(context).size.width / 30,
                  fontWeight: FontWeight.normal,
                ),
              ),
              Text(
                role,
                style: TextStyle(
                  color: color_grey_text,
                  fontSize: MediaQuery.of(context).size.width / 35,
                  fontWeight: FontWeight.normal,
                ),
              ),
            ],
          ),
          Spacer(),
          IconButton(
            icon: Icon(
              Icons.arrow_forward_ios,
              size: MediaQuery.of(context).size.height / 40,
            ),
            onPressed: () {
              Navigator.push(context, MaterialPageRoute(builder: (context) =&gt; DetailUserPage()));
            },
          ),
        ],
      );
    }
  
    Widget notSignIn() {
      return Padding(
        padding:
            EdgeInsets.only(left: 50.0, right: 50.0, top: 30.0, bottom: 30.0),
        child: RaisedGradientButton(
          child: Text(
            'Login',
            style: TextStyle(
                color: color_white,
                fontSize: MediaQuery.of(context).size.width / 25),
          ),
          gradient: LinearGradient(
            colors: &lt;Color&gt;[color_blue, color_green],
          ),
          onPressed: () {
            Navigator.push(
                context, MaterialPageRoute(builder: (context) =&gt; LoginPage()));
          },
        ),
      );
    }
  }
  </code></pre>
  
  <p>And this is class SessionManager for create function of shared_preferences:</p>
  
  <pre><code>class SessionManager {
  
    .....
  
    getStatusLogin() async {
      SharedPreferences preferences = await SharedPreferences.getInstance();
      int status = preferences.getInt("status");
      return status;
    }
  
    ....
  
  }
  </code></pre>