【发布时间】:2020-07-16 15:52:24
【问题描述】:
我查询了 firebase 并得到了预期的答案,但是,当我返回 String 时,它是 null ...在方法内部它不是 null!
class Util {
final Firestore firestore = Firestore.instance;
String name;
List<User> users = [];
String getNomeById(bool retirada, String userId) {
firestore
.collection('users')
.where(FieldPath.documentId, isEqualTo: userId)
.snapshots()
.listen((snapshot) {
users = snapshot.documents.map((d) => User.fromDocument(d)).toList();
if (retirada) {
name = users[0].name;
// print(name); name is here!
} else {
name = 'Other';
}
});
return name; // IS NULL
}
}
【问题讨论】:
-
为什么你会从 firestore 获得
Stream?是否有任何特殊原因,或者您只是想获取该查询返回的内容? -
@ChristopherMoore 我只是想得到返回的东西
标签: firebase dart google-cloud-firestore