I'm getting null value in flutter build method for this code.
(在此代码的flutter构建方法中,我得到了空值。)
String userEmail;
var data;
String userName;
@override
void initState(){
setState(() {
getUserName();
print(userName);
});
super.initState();
}
void getUserName() async {
MyFirebaseAuth myFirebaseAuth = MyFirebaseAuth();
userEmail =await myFirebaseAuth.getUser();
if (userEmail == null){
print("no user");
}
else{
data =await fb.firestore().collection('users').doc(userEmail).get().then((onValue){
return onValue.data();
});
print(data);
print(data['name']);
userName = data['name'];
print("Username is $userName");
}
}
output is
(输出是)
Performing hot restart...
(正在执行热重启...)
Restarted application in 759ms.
(在759毫秒内重新启动应用程序。)
null {entries: 3, name: xmr} vraj Username is xmr(空{输入:3,名称:xmr} vraj用户名是xmr)
ask by Susan Pandit translate from so