flutter - 如何在flutter中将文档快照转换为Stream数据?

标签 flutter dart google-cloud-firestore

DocumentSnapshot doc = await userRef.document(widget.currentuserId).get();
user = User.fromDocument(doc);
bioController.text = user.bio;
usernameController.text = user.username;
displayNameController.text = user.displayName;

如何在流数据中进行转换?

我尝试了这个,但是有一些错误我无法弄清楚:
Stream<DocumentSnapshot> doc = await userRef.document(widget.currentuserId).snapshots();
user = User.fromDocument(doc);
bioController.text = user.bio;
usernameController.text = user.username;
displayNameController.text = user.displayName;

最佳答案

如果使用get(),则得到Future<DocumentSnapshot>,则需要使用snapshots

Stream<DocumentSnapshot> stream = userRef.document(widget.currentuserId).snapshots();
stream.listen((snapshot) {
  // snapshot is DocumentSnapshot
});

关于flutter - 如何在flutter中将文档快照转换为Stream数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62105300/

相关文章:

flutter 网页 http.get 返回 "Unsupported operation: Platform._version"

flutter - 是否可以从 Material 库导入单个文件来访问其私有(private)字段?

regex - 在 Dart 中使用动态(可变)字符串作为正则表达式模式

Dart:将派生类的比较运算符委托(delegate)给基类的比较运算符

for-loop - 列表值未在dart for loop中更改

ios - 如何在 firestore 数据库中使用 swift 更新数组中的对象( map )?

swift - 从 map 中删除一项会删除所有项目

Flutter BLoC mapEventToState 仅在事件的第一次调用时才被调用,并且不会在下次触发该事件时调用

json - Dart问题与获取JSON数据

javascript - React Native 平面列表(无限滚动)正在从 Firebase 返回重复记录