'Uber Clone Flutter: Firebase-Flutter User Information Problem: Keep recieveing NULLs when changing screen & Hot Restart
My teammates and I are developing an uber-like Flutter-based application for our senior project. We are also linking our application to firebase. The code was working fine, however, 3 days ago we tried running the code and we faced a sudden error with storing the user information after signing in and authenticating the user. Error Recieved We saved a snapshot of the users Data in another file and then we would use it to display their info on other screens. It was working fine and suddenly it stopped and flutter is behaving very strangely. We fixed that error however we are still facing a problem, whenever we hot restart the app to check chhanges again the error mentioned before would appear:
The piece of code used to authenticate the user in the loginScreen fAuth is a variable declared in another file, ccUser is also a type datasnapshot stored in the other file as well.
try {
final UserCredential usercred = await fAuth.signInWithEmailAndPassword(
email: emailTextEdittingController.text,
password: passwordTextEdittingController.text);
User user = usercred.user;
if (usercred != null) {
DatabaseReference repRef =
FirebaseDatabase.instance.ref().child('medics');
repRef.child(user.uid).once().then((repKey) {
final snap = repKey.snapshot;
if (snap.value != null) {
ccUser = snap;
Navigator.pushNamedAndRemoveUntil(
context, MainScreen.idScreen, (route) => false);
displayToastMessage('Successfully Logged In!', context);
} else {
Fluttertoast.showToast(msg: "Error Logging In OOOPSSSSS");
fAuth.signOut();
}
});
}}
Thank you!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
