簡體   English   中英

Google登錄-Flutter

[英]Google sign in - Flutter

使用GoogleSignIn插件后,如何設置標准頭像,並在登錄Google后更改為Google PhotoURL? 我可以很好地使用_handlesignin函數,但登錄后無法更改狀態? (我在嘗試根據登錄狀態創建登錄/退出按鈕時遇到類似的問題)

我認為這將是某種類型的if函數,然后是else,但是無法使其正常工作。

是的,您是正確的,它需要一些if else語句。 我認為您正在尋找auth.currentUser()函數來檢查用戶登錄狀態和發出狀態。

以下代碼檢查用戶登錄狀態,如果用戶已登錄,則放置用戶個人資料照片。

  FirebaseAuth auth; //firebase auth
  FirebaseUser user; // firebase user

  var imageUrl = "assets/image.png";  //you can use a image 
  //as a default image that would be replaced later with the profile photo


  Widget userProfilePhoto()
  {
    return Center(
        child: Container(
          height: 100.0,
          width: 100.0,
          decoration: BoxDecoration(
            shape: BoxShape.circle,
            image: DecorationImage(
              fit : BoxFit.fill,
              image: NetworkImage(userurl)
            )
          ), 
        )
      ),
  }


  void checkUser()
  {
    //Check if the user is signned in or not with the currentUser() function
    if(auth.currentUser() != null)
    {
      setState((){
        userImageUrl = user.photoUrl;
        //if the user is signned in then set the url to be the image url
      });
    }
    else
    {
      //call signin method to make the user signin
      signIn();
    }
  }

暫無
暫無

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

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