我正试图从我的Firebase数据库中显示用户的基本信息列表。
我知道如何显示Users集合的所有用户,但是我不知道如何在列表视图中提取每个用户的basicInfo。
final CollectionReference userCollection =
Firestore.instance.collection('Users');
class FirebaseFirestoreService {
static final FirebaseFirestoreService _instance = new
FirebaseFirestoreService.internal();
factory FirebaseFirestoreService() => _instance;
FirebaseFirestoreService.internal();
Stream<QuerySnapshot> getUserList({int offset, int limit}) {
Stream<QuerySnapshot> snapshots = userCollection.snapshots();
if (offset != null) {
snapshots = snapshots.skip(offset);
}
if (limit != null) {
snapshots = snapshots.take(limit);
}
return snapshots;
}
}
@override
void initState() {
super.initState();
items = new List();
cardSub?.cancel();
cardSub = db.getUserList().listen((QuerySnapshot snapshot) {
final List<CardModel> cards = snapshot.documents
.map((documentSnapshot) => CardModel.fromMap(documentSnapshot.data))
.toList();
setState(() {
this.items = cards;
});
});
}
如何在列表视图中显示单个用户的basicInfo?