'how to make my splash screen goes to homePage when the user is already loged in

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await EasyLocalization.ensureInitialized();
  await Firebase.initializeApp();

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    User? user = FirebaseAuth.instance.currentUser;
    return MaterialApp(
        localizationsDelegates: context.localizationDelegates,
        supportedLocales: context.supportedLocales,
        locale: context.locale,
        title: 'Email And Password',
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          // This is the theme of your application.

          primarySwatch: Colors.red,
        ),
        home: AnimatedSplashScreen(
          splash: Image.asset("assets/mop.png"),
          duration: 1000,
          splashTransition: SplashTransition.fadeTransition,
          backgroundColor: Colors.green.shade300,
          nextScreen: nextUii(),
        ));
  }
  nextUii() {
    User? user = FirebaseAuth.instance.currentUser;
    if (user != null) {
      Timer(Duration(seconds: 5), () => SelectingLanguage());
    } else {
      Timer(Duration(seconds: 5), () => HomeScreen());
    }
  }
}
 

i face the error of type null is not a subtype of type 'widget' i just wanna make the app while running goes to home page when the user il already loged in otherwithe to the selecting Language UI thanks.



Solution 1:[1]

Store the isLoggedIn state in your device using shared preferences.

  SharedPreferences sp;
        sp=getSharedPreferences("SD", Context.MODE_PRIVATE);
        SharedPreferences.Editor ed=sp.edit();
        ed.putBoolean("isLoggedIn",true);
        ed.commit();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
Boolean isLoggedIn= preferences.getBoolean("isLoggedIn", "");
if(isLoggedIn){

startActivity(Intent(this,HomeActivity.class));

}else{
startActivity(Intent(this,LoginActivity.class));
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Narendra_Nath