@H_403_2@
我想获得Future返回值并像变量一样使用它.
我有这个Future函数
我有这个Future函数
Future<User> _fetchUserInfo(String id) async { User fetchedUser; await Firestore.instance .collection('user') .document(id) .get() .then((snapshot) { final User user = User(snapshot); fetchedUser = user; }); return fetchedUser; }
我希望得到这样的价值
final user = _fetchUserInfo(id);
但是,当我尝试使用这样的时候
new Text(user.userName);
Dart无法识别为User类.它说动态.
我如何获得返回值并使用它?
我首先做错了吗?
任何帮助表示赞赏!
解决方法
@H_403_2@