I have a problem signing out the current user from my app
the method I am using is as follows:
....
onPressed:_signOut
//jump to function
void _s
Most demos I've looked at only logout of Firebase using a command like _auth.signOut();
This doesn't appear to exist anymore (see Collin's reply above):
_googleSignIn.signOut()
So, I had to use this one method to signout/logout of Google.
_googleSignIn.disconnect();
Firebase auth's signOut
method is asynchronous. You should make your _signOut
method async
.
Future<void> _signOut() async {
await FirebaseAuth.instance.signOut();
}
so that the call to runApp
occurs after the user is signed out.
You should also call _googleSignIn.signOut()
when logging out if you want signIn
to present the user with an authentication dialog instead of silently and automatically re-using the current Google user.
If every answer above is not working, maybe a Page is laying above everything else, then use Navigator.of(context).pop();
to pop the page.
I've searched hours looking for a mistake that wasn't even there just for this small mistake.
You need to have an Instances of FirebaseAuth
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
And Then
_signOut() async {
await _firebaseAuth.signOut();
}
First create an instance of FirebaseAuth like so
FirebaseAuth auth = FirebaseAuth.instance;
Then add this to either your logout button or any means you wish to use for the logout.
signOut() async {
await auth.signOut();
}
You can also create a function and then call the signOut within your button like so
import 'package:flutter/material.dart';
class SignOut extends StatefulWidget {
@override
_ SignOut State createState() => _ SignOut State();
}
class _ SignOut State extends State< SignOut > {
FirebaseAuth auth = FirebaseAuth.instance;
signOut() async {
await _firebaseAuth.signOut();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Container(
child: RaisedButton(
onPressed: () {
signOut();
},
)
),
),
);
}
}
You decide.