这是数据库类。我正在尝试从fetchprojects
函数中获取数据到将来的构建器中,但无法做到这一点。
List<Project> fetchProjects(QuerySnapshot snapshot) {
return snapshot.documents.map((e) {
return Project(
id: e.data['id'],
title: e.data['title'],
description: e.data['description'],
prequisites: e.data['prequisites'],
complexity: e.data['complexity'],
affordability: e.data['affordability'],
duration: e.data['duration'],
members: e.data['members'],
contact: e.data['contact']);
}).toList();
}
// get brews stream
//
Stream<List<Project>> get projects {
return projectCollection.snapshots().map(fetchProjects);
}
}
答案 0 :(得分:0)
感谢您的帮助!此代码段对我有用。您可以通过返回listviewBuilder而不是center来创建卡片。
Widget build(BuildContext context) {
return StreamBuilder(
stream: Firestore.instance.collection('projects').snapshots(),
builder: (context,snapshot){
if(!snapshot.hasData)
return Text('data is loading');
return Center(child: Text(snapshot.data.documents[0]['title']),);
}
);}