In this Project I’m using firebase authentication and for changing homepage of the MaterialApp
a StreamBuilder
is implemented at MaterialApp
‘s home section but its not working as expected.
home of the MaterialApp,
home: StreamBuilder(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, snapshot) {
if (snapshot.hasData) {
Constants.firebaseUser = snapshot.data!;
return FutureBuilder(
future: FirebaseServices.getUserType(snapshot.data!.uid),
builder: (context, snap) {
if (snap.data == UserType.doctor) {
return const DoctorHomePage();
} else if (snap.data == UserType.patient) {
return const UserHomePage();
} else if (snap.data == UserType.admin) {
return const AdminHome();
} else {
return const LoadingSplash();
}
});
} else {
return const LoginPage();
}
}));
It should change the homepage from login to any of those pages at the time of successful login.
But it only navigating to those home page only after restart.
PS. here I’m using another future function to find the category in which the user falls in.
2
Answers
You can use getxcontroller
There might be several reasons why your Firebase authentication stream isn’t working. Here are some troubleshooting measures you may take:
Examine your Firebase settings: Check your Firebase setup, including the Firebase API key and the project ID. Also, ensure that authentication is enabled in your Firebase project.
Examine your import statements: Check that you’ve included the Firebase authentication libraries in your code. This is usually firebase/auth and firebase/app.
Examine your code for errors: Examine your code to ensure that there are no syntax mistakes or other problems that might be causing the stream to fail.
Examine the Firebase console: Check the Firebase console to check if any errors have occurred.