I wanted to program a initial start up for new users, simply for them to input their initial Username, Email, possibly a password, and
If you are planning to use Firebase for authentication. There is another method you can do to check whether the user is logged in or not in your MaterialApp
without using the Wrapper
class. FirebaseAuth returns the current user with the following method. To do that, you need to also consider state management
in your project.
initialRoute:FirebaseAuth.instance.currentUser != null ? '/home' : '/welcome',
CodePudding user response:
I couldn't quite get your issue but as I understand, I advice that below code,so you can controll check new user by this approach firstly, set a bool by the sharedPreferences package
TextButton get isNewUserButton=> TextButton(onPressed: ()async{
final prefs = await SharedPreferences.getInstance();
prefs.setBool('isNewUser',true);
}, child: const Text("Get Started"));
then,
void main()async {
final prefs = await SharedPreferences.getInstance();
final showHomePage = prefs.getBool('isNewUser') ?? false;
runApp(MaterialApp(
title: 'App',
themeMode: ThemeMode.system,
theme: MyThemes.lightTheme,
darkTheme: MyThemes.darkTheme,
home: showHomePage ? MyApp() : NewUserSignPage ,
));
}
if user sign out you can use this code
TextButton get signOutButton=> TextButton(onPressed: ()async{
final prefs = await SharedPreferences.getInstance();
prefs.setBool('isNewUser',false);
}, child: const Text("Sign Out"));
CodePudding user response:
You can use named routing. In your MaterialApp, you can set a boolean whether if the user is logged in or not.Such that;
initialRoute: isUserLoggedIn == null ? '/login-screen' : '/home-screen';