簡體   English   中英

我正在嘗試使用 Firebase 在 Flutter 中使用 Google 注銷,但它不起作用

[英]I'm trying to signOut with google in Flutter with Firebase and it doesn't work

我正在使用 Flutter 和 Firebase。 當我嘗試使用電子郵件和密碼注銷時,效果很好,但當我嘗試使用谷歌時,它不起作用。

這是我的代碼:`

try {
    switch (user.providerData[0].providerId) {
    case 'password':
      await FirebaseAuth.instance.signOut();
      break;
    case 'google.com':
      final GoogleSignIn googleSignIn = GoogleSignIn();
      await googleSignIn.signOut();
      break;
}
} on FirebaseAuthException catch (e) {
    showAuthException(e, context);
}

`

我正在嘗試這個

`

try {
    switch (user.providerData[0].providerId) {
    case 'password':
      await FirebaseAuth.instance.signOut();
      break;
    case 'google.com':
      final GoogleSignIn googleSignIn = GoogleSignIn();
      await googleSignIn.signOut();
      break;
}
} on FirebaseAuthException catch (e) {
    showAuthException(e, context);
}

`

請參考這段代碼:),這樣就可以了。


你的代碼:

final GoogleSignIn googleSignIn = GoogleSignIn();
await googleSignIn.signOut();

問題是您已經從該變量創建了 googleSignIn 變量和 signOut。

您也可以嘗試使用googleSignIn.isSignedIn(); 這將返回布爾值。


工作代碼。

class GoogleServiceProvider extends ChangeNotifier {
  static final GoogleSignIn _googleSignIn = GoogleSignIn(); // <----

  GoogleSignInAccount? _user;

  GoogleSignInAccount? get user => _user;

  Future<GoogleSignInAccount?> logInWithGmail() async {
    final googleUser = await _googleSignIn.signIn();
    if (googleUser != null) {
      _user = googleUser;
      notifyListeners();
    }
    return null;
  }

  Future logOut() async {
    await _googleSignIn.signOut();
    notifyListeners();
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM