Issue
Main Dart:
Widget build(BuildContext context) {
return StreamProvider<MyUser?>.value(
value: AuthService().user,
initialData: null,
child: MaterialApp( //code for material dart
Wrapper Widget:
Widget build(BuildContext context) {
final user = Provider.of<MyUser?>(context);
print(user);
if (user == null) {
print('no one logged in');
} else {
print(user.uid);
}
return user == null ? LoginPage() : NavigationBar();
}
So I'm trying to load the login page whenever user is null, but I only logged in the first time and now it stays logged in even after deleting that account from firebase console.
Output after hot restart:
Restarted application in 935ms.
flutter: null
flutter: no one logged in
flutter: Instance of 'MyUser'
flutter: ETBVvt2A0JggH8KSrgdLh3DP8cG3
I don't get why the first time it returns 'no one logged in' but it runs a second time too and returns the uid of the user that is logged in.
The logout button doesn't work either. It does't return an error or anything, it just doesn't produce any output.
Here is the signOut button method:
//method
final FirebaseAuth _auth = FirebaseAuth.instance;
Future signOut() async {
try {
return await _auth.signOut();
} catch (error) {
print(error.toString());
return null;
}
Signout button:
onPressed: () async {
dynamic result = await _auth.signOut();
if (result == null) {
print('error signing out');
} else {
print('signed out');
Navigator.pushReplacementNamed(
context, LoginPage.routeName);
}
},
Solution
Apparently the problem wasn't with firebase but with the custom button I had built. I didn't assign the onPressed properly and the logout button wasn't working because of that.
Answered By - ceptic
Answer Checked By - Clifford M. (JavaFixing Volunteer)