我尝试了这种逻辑。有了它,我可以打印所需的数据,但是不能将其保存到局部变量中。
{
var temp;
//gets the user details using firestore and uid
final result = firestoreServices.getUserDetails(user.uid);
result.then((data) {
temp = data['role'];
}, onError: (e) {
print(e);
});
print("temp: --> $temp");
return UserModel(uid: user.uid, role: userRole);
}
如果我打印温度,它将打印为空。
我不想使用将来的构建器。我有什么办法吗?
答案 0 :(得分:0)
尝试一下
{
var temp;
//gets the user details using firestore and uid
final result = await firestoreServices.getUserDetails(user.uid);
temp = data['role'];
print("temp: --> $temp");
return UserModel(uid: user.uid, role: userRole);
}