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();
}
}
1 回答
是的你是对的,它需要一些if else声明 . 我认为你正在寻找 auth.currentUser() 函数来检查用户登录和点唱的状态 .
以下代码检查用户登录状态,如果用户已登录,则放置用户 Profiles 照片 .