title: How to properly implement logout functionality in flutter app?
body: <p>I want to implement logout functionality in my flutter app. There is a button in my side menu drawer logout and when the user presses the button I want the user to navigate to login screen and pop all other screens.</p>
  
  <p>I have tried to do it and my code is</p>
  
  <pre><code>SharedPreferences prefs = await SharedPreferences.getInstance();
  await prefs.remove('userPreference');
  await Future.delayed(Duration(seconds: 2));
  
  Navigator.of(context)
      .popUntil(ModalRoute.withName(Navigator.defaultRouteName));
  
  Navigator.of(context).pushReplacement(
       MaterialPageRoute(
          builder: (BuildContext context) =&gt; 
                  LoginScreen(),
       )
  );
  </code></pre>