I am trying to auto login user and Navigate the user to either Admin, Student or Teacher page after loging in with firebase and fetching there data successfull, everything is good except when I added the three choices 'Admin, Student or Techer' in an initState with three if statements It doesn't do autologin but when I replace them with one process It works So I don't know what is the proplem, every thing is fine, it finds the user, It fetchs its data and prints to be sure and navigates according to the userType which is not null, but when I do restart It doesn't do autologin. My code :
@override
void initState() {
super.initState();
print(userType);
FirebaseAuth.instance.currentUser().then((res) {
print(res);
if (res != null) {
if (userType == 'Student') {
Navigator.pushReplacementNamed(context, '/StudentsPage');
} else if (userType == 'Teacher') {
Navigator.pushReplacementNamed(context, '/TeacherPage');
} else if (userType == 'Admin') {
Navigator.pushReplacementNamed(context, '/AdminPage');
}
}