String ok ="/login";
String _loggedInFunction(){
FirebaseAuth.instance
.authStateChanges()
.listen((User? user) {
if (user == null) {
ok = "/login";
}else{ ok = "/home";}
print(ok);
print(user);
});
print("Reading 1st");
return ok;
}
I can't be able to understand whether the FirebaseAuth.instance.... is an asynchronous function. Because second statement is running before the first one, but how can I apply "await" keyword here, While applying "await" keyword before FirebaseAuth.instance... .it's showing it is not a Future event.
And also I can you explain me why I can't be able return "ok" variable which is inside if statement directly, it's showing me an error.
I used this code to skip the login if the user restart the app. Do you have any recommended code for this purpose??
Output of the above code
I/flutter ( 6405): Reading 1st
I/flutter ( 6405): /home