title: My flutter app logs out after hot restart,Cannot make app stay logged in even after restart
body: <p>i implemented login  after onboard screen and logged in but unfortunately each time i restart my app i am brought back to the welcome page.i also want to implement a splash screen   but don't know how to add it in the <em>MyApp</em> material root  widget since i have returned the introduction/on boarding page and set the welcome page to come after it.I  also want to find a way to check auth state after one time introduction/on boarding screen. I'll appreciate</p>
  <pre><code>    int initScreen;
  
     Future&lt;void&gt; main() async {
     WidgetsFlutterBinding.ensureInitialized();
         await Firebase.initializeApp();
  
         //on Board Screen Intialization
   SharedPreferences prefs = await SharedPreferences.getInstance();
         initScreen = prefs.getInt('initScreen');
           await prefs.setInt(&quot;initScreen&quot;, 1);
  
             runApp(MyApp());
               }
  
       class MyApp extends StatelessWidget {
         // This widget is the root of your application.
      @override
       Widget build(BuildContext context) {
     return MaterialApp(
       debugShowCheckedModeBanner: false,
            home: Introduction(),
        initialRoute: initScreen == 0 || initScreen == null ? 'onboard' : 'home',
    routes: {
      'home': (context) =&gt; WelcomeScreen(),
      'onboard': (context) =&gt; Introduction()
          },
         );
            }
           }
  
  
   class Login extends StatefulWidget {
   const Body({Key key}) : super(key: key);
  
    @override
     _LoginState createState() =&gt; _LoginState();
    }
  
          class _LoginState extends State&lt;Login&gt; {
     TextEditingController _email = TextEditingController();
      TextEditingController _password = TextEditingController();
       isLoading = false;
  
            @override
    Widget build(BuildContext context) {
            Size size = MediaQuery.of(context).size;
              return Scaffold(
                    body: Background(
          child: isLoading == false
              ? SingleChildScrollView(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: &lt;Widget&gt;[
                      Text(
                        &quot;LOGIN&quot;,
                        style: TextStyle(
                            fontWeight: FontWeight.bold, fontSize: 20),
                      ),
                      SizedBox(height: size.height * 0.03),
                      SvgPicture.asset(
                        &quot;assets/icons/login.svg&quot;,
                        height: size.height * 0.35,
                      ),
                      SizedBox(height: size.height * 0.03),
                      TextFieldContainer(
                        child: TextFormField(
                          controller: _email,
                          cursorColor: kPrimaryColor,
                          decoration: InputDecoration(
                            icon: Icon(
                              Icons.email,
                              color: kPrimaryColor,
                            ),
                            hintText: &quot;Email&quot;,
                            border: InputBorder.none,
                          ),
                        ),
                      ),
                      TextFieldContainer(
                        child: TextFormField(
                          controller: _password,
                          obscureText: true,
                          cursorColor: kPrimaryColor,
                          decoration: InputDecoration(
                            hintText: &quot;Password&quot;,
                            icon: Icon(
                              Icons.lock,
                              color: kPrimaryColor,
                            ),
                            suffixIcon: Icon(
                              Icons.visibility,
                              color: kPrimaryColor,
                            ),
                            border: InputBorder.none,
                          ),
                        ),
                      ),
                      RoundedButton(
                        text: &quot;LOGIN&quot;,
                        press: () {
                          setState(() {
                            isLoading = true;
                          });
                          AuthClass()
                              .SignIn(
                                  _email.text.trim(), _password.text.trim())
                              .then((value) {
                            if (value == 'Welcome') {
                              setState(() {
                                isLoading = false;
                              });
                              Navigator.pushAndRemoveUntil(
                                  context,
                                  MaterialPageRoute(
                                      builder: (context) =&gt; Home()),
                                  (route) =&gt; false);
                            } else {
                              setState(() {
                                isLoading = false;
                              });
                              ScaffoldMessenger.of(context).showSnackBar(
                                  SnackBar(content: Text(value)));
                            }
                          });
                        },
                      ),
                      SizedBox(height: size.height * 0.03),
                      AlreadyHaveAnAccountCheck(
                        press: () {
                          Navigator.push(
                            context,
                            MaterialPageRoute(
                              builder: (context) {
                                return SignUpScreen();
                              },
                            ),
                          );
                        },
                      ),
                    ],
                   ),
                )
                : Center(
                  child: CircularProgressIndicator(),
                )));
             }
            }
  
                     
        class AuthClass {
          FirebaseAuth _auth = FirebaseAuth.instance;
  
        //Create account
       Future&lt;String&gt; createAcount(String email, String password) async {
         try {
    await _auth.createUserWithEmailAndPassword(
        email: email, password: password);
            return &quot;Account Successifuly Created&quot;;
            } on FirebaseAuthException catch (e) {
    if (e.code == 'weak-password') {
      return 'The password provided is too weak.';
           } else if (e.code == 'email-already-in-use') {
      return 'The account already exists for that email';
         }
       } catch (e) {
          return 'Error ocurred';
      }
      }
  
     //SignIn User
   Future&lt;String&gt; SignIn(String email, String password) async {
  try {
    await _auth.signInWithEmailAndPassword(email: email, password: password);
    return 'Welcome';
    } on FirebaseAuthException catch (e) {
    if (e.code == 'user-not-found') {
      return 'No user found for that email.';
    } else if (e.code == 'wrong-password') {
      return 'Wrong password provided for that user.';
    }
    }}
  
    //ResetPAssword
  
  
    //SignOut
    void signOut() {
      _auth.signOut();
    }
  
    //try
    Future&lt;String&gt; Reset(
      String email,
    ) async {
      try {
        await _auth.sendPasswordResetEmail(
          email: email,
        );
        return 'Email sent';
      } catch (e) {
        return 'Error Occured';
      }
    }
  
  }
  </code></pre>