title: Automatically send to home or register page on Flutter
body: <p>I'm using this way to authenticate the user and redirect to the pages but the first &quot;void initState&quot; appears as unusable and when the user is not logged in it ends up not redirecting to Welcome(); What can be wrong?</p>
  <pre><code>class SplashPage extends StatefulWidget {
    @override
    _SplashPageState createState() =&gt; _SplashPageState();
  }
  
  class _SplashPageState extends State&lt;SplashPage&gt; {
    Future _loggedUserValidation() async {
      FirebaseAuth auth = FirebaseAuth.instance;
  
      FirebaseUser loggedUser = await auth.currentUser();
      if (loggedUser != null) {
        Navigator.push(context, MaterialPageRoute(builder: (context) =&gt; Home()));
      } else {
        @override
        void initState() {
          super.initState();
  
          Future.delayed(Duration(seconds: 2)).then((value) =&gt;
              Navigator.pushReplacement(
                  context, MaterialPageRoute(builder: (context) =&gt; Welcome())));
        }
      }
    }
  
    @override
    void initState() {
      _loggedUserValidation();
      super.initState();
    }
  </code></pre>