首页 文章

Google登录 - Flutter

提问于
浏览
0

使用GoogleSignIn插件后,如何设置标准头像,登录Google后更改为Google PhotoURL?我可以使用_handlesignin函数,但登录后无法更改状态? (我尝试根据登录状态创建登录/退出按钮时遇到类似问题)

我认为它会是某种类型的if函数,但是无法让它工作 .

1 回答

  • 1

    是的你是对的,它需要一些if else声明 . 我认为你正在寻找 auth.currentUser() 函数来检查用户登录和点唱的状态 .

    以下代码检查用户登录状态,如果用户已登录,则放置用户 Profiles 照片 .

    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();
        }
      }
    

相关问题