content: Column(
children: <Widget>[
_buildUserPic1(),
_buildUserPic2()
],
),
以下是我尝试获取使用Google Firebase身份验证登录的用户的照片的两种方法。
Container _buildUserPic(){
return Container(
child: Image.network(
user.photoUrl
),
);
}
第二种方法是
Container _buildUserPic2(){
return Container(
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: NetworkImage(widget.url),
)
),
)
);}
第一个成功生成个人资料图片,但另一个给出错误。什么是获取图像的正确方法?我应该使用异步方法来获取图像吗?
编辑:
user
是FirebaseUser
的实例。
widget.url
用于访问String url
(在有状态的小部件中)
final String url = user.photoUrl;
Edit2:
final FirebaseAuth firebaseauth = FirebaseAuth.instance;
final GoogleSignIn gsa = new GoogleSignIn();
Future<FirebaseUser> _signIn() async {
GoogleSignInAccount googleSignInAccount = await gsa.signIn();
GoogleSignInAuthentication googleSignInAuthentication = await googleSignInAccount.authentication;
FirebaseUser firebaseUser = await firebaseauth.signInWithGoogle(
idToken: googleSignInAuthentication.idToken,
accessToken: googleSignInAuthentication.accessToken,
);
user = firebaseUser;
googleSignIn = gsa;
}