today I tried to build 2 screens "login with GG" and "logout redirect to login screen". Succeed! But when I log in again, Previous gg account logged in immediately without requiring sign-in popup. On my device remember logged account. How to sign out completely and sign-in again with the other accounts. Here my code: I have 'the home page with login with google' and 'home-center page with signout button'. Besides, I have api.dart to log in and log out, and the main page using routes to 2 pages. - Main Page:
routes: {
"home-page": (context) => MyHomePage(),
"game-center": (context) => GameCenterPage(),
},
home: MyHomePage(),
- Api.dart:
class FBApi {
static FirebaseAuth _auth = FirebaseAuth.instance;
static GoogleSignIn _googleSignIn = GoogleSignIn();
FirebaseUser firebaseUser;
FBApi(FirebaseUser user) {
this.firebaseUser = user;
}
static Future<FBApi> signInWithGoogle() async {
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
final FirebaseUser user = await _auth.signInWithGoogle(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
assert(user.email != null);
assert(user.displayName != null);
assert(await user.getIdToken() != null);
final FirebaseUser currentUser = await _auth.currentUser();
assert(user.uid == currentUser.uid);
return FBApi(user);
}
static Future<void> signOut() async {
await _auth.signOut().then((_) {
print("***** log out...what the hell?");
// Navigator.of(context).pushNamedAndRemoveUntil("/login",
ModalRoute.withName("/home"));
});
}
}
- gameCenter.dart:
onPressed: () async {
_signOut();
Navigator.of(context).pushNamedAndRemoveUntil("home-page", ModalRoute.withName("game-center"));
},
- home.dart
class MyHomePage extends StatelessWidget {
Future<bool> _loginUser() async {
final api = await FBApi.signInWithGoogle();
if (api != null) {
return true;
} else {
return false;
}
}
...