小编K U*_*yay的帖子

使用 Firebase Stream 作为 Flutter 中另一个 Stream 的输入?

上下文:我有两个可以正常工作的 Firebase Stream,它们获取 i) 用户配置文件列表(“用户”集合),以及 ii)属于每个用户配置文件的位置列表(“位置”集合),以及然后将它们映射到自定义用户和位置模型。

用户流:

class DatabaseService {

final String uid;
final String friendUid;
final String locationId;
DatabaseService({ this.uid, this.locationId, this.friendUid });

// collection reference for users
final CollectionReference userCollection = FirebaseFirestore.instance.collection('users');

// get users stream
Stream<List<CustomUserModel>> get users {

final FirebaseAuth auth = FirebaseAuth.instance;
final User user = auth.currentUser;
final uid = user.uid;

List<CustomUserModel> userList = [];

List<CustomUserModel> _streamMapper(DocumentSnapshot snapshot) {
  CustomUserModel individualUser = CustomUserModel(
    uid: snapshot.id,
    name: snapshot.data()['name'],
    username: snapshot.data()['username'],
    email: snapshot.data()['email'],
  );
  userList.add(individualUser);
  return …
Run Code Online (Sandbox Code Playgroud)

firebase flutter google-cloud-firestore

1
推荐指数
1
解决办法
52
查看次数

标签 统计

firebase ×1

flutter ×1

google-cloud-firestore ×1