I have questions regarding singing out a user while using Firebase Authentication (e-Mail & password) on a Flutter Application (iOS). I searched a lot but I just can't get the last bit of understanding my problem.
So in my app I have multiple Screens where I route through with the Navigator.pushNamed(...). The User is able to navigate to a settings screen where he should be able to log out.
class _OptionScreenState extends State<OptionScreen> {
FirebaseAuth _auth = FirebaseAuth.instance;
_signOut() async {
try {
await _auth.signOut();
} catch (e) {
print(e.toString());
}
}
@override
Widget build(BuildContext context) {
(...some more code here....)
ListTile(
title: Text(
'Logout',
style: TextStyle(fontSize: 25.0),
),
onTap: () async {
await _signOut();
Navigator.pushReplacementNamed(context, 'welcome_screen');
},
The Welcome_Screen is the starting screen where the user is able to choose between logging in or singing up.
After being pushed to the welcome screen I get the following error:
Receiver: null Tried calling: uid flutter: NoSuchMethodError: The getter 'uid' was called on null.
So my questions are:
- I create the authentication Instance everywhere I need it. Do I need one global Instance or do I have to sing out every instance I created? I have the feeling that other "screens" are still active and after logging of they miss an active user (I hope this is understandable) if true: Can I close those screens? So that the user starts with a "fresh" app after logging out?
- Is there a solution to that (haha)
- Should I use Provider to share one single _auth instance?