dart - 谷歌登录 - 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();
}
}
推荐阅读
- html - 如何使用css在中心对齐中设置单个子元素?
- python - 在 Google Cloud Platform 上部署应用程序 - pyzbar 的 ImportError
- c - 在 ## 运算符存在的情况下,可变参数 GNU C 预处理器宏的惊人扩展
- python - google-datastore 获取正确的 blob 项密钥以供下载
- java - 通过 gradle 配置 JOOQ Codegen 时找不到 H2 驱动程序
- charts - 在 javascript 中使用 get 函数的结果
- python - 如何导出带有 utf-8 错误的串联 csv
- jmeter - jmeter 执行与 Jenkins 中先前构建的比较
- marklogic - xdmp:email 和 AWS SES
- c# - ASP.NET Core SaveChangesAsync 不会保存所有内容