Flutter _MapStream<;查询快照、列表<;模型>&燃气轮机;
我想在打印响应时使用model和StreamBuilder从firestore检索数据,它总是这样 “\u MapStream”的实例 飞镖Flutter _MapStream<;查询快照、列表<;模型>&燃气轮机;,flutter,dart,flutter-provider,flutter-state,Flutter,Dart,Flutter Provider,Flutter State,我想在打印响应时使用model和StreamBuilder从firestore检索数据,它总是这样 “\u MapStream”的实例 飞镖 StreamBuilder<List<Model>>( stream: firestoreProvider.getFiveList(), builder: (context, snapshot) { if(snapshot.connectionState == ConnectionState.
StreamBuilder<List<Model>>(
stream: firestoreProvider.getFiveList(),
builder: (context, snapshot) {
if(snapshot.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator(strokeWidth: 3,),);
} else if(snapshot.connectionState == ConnectionState.done) {
return ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
var doc = snapshot.data[index];
return ListTile(
);
}
);
} else {
return Center(child: Text("Null"),);
}
},
)
StreamBuilder(
流:firestoreProvider.getFiveList(),
生成器:(上下文,快照){
if(snapshot.connectionState==connectionState.waiting){
返回中心(子项:圆压指示器(行程宽度:3,),);
}else if(snapshot.connectionState==connectionState.done){
返回ListView.builder(
收缩膜:对,
物理学:NeverscrollableScroll物理学(),
itemCount:snapshot.data.length,
itemBuilder:(上下文,索引){
var doc=快照数据[索引];
返回列表块(
);
}
);
}否则{
返回中心(子项:文本(“空”),);
}
},
)
提供者.省道
Stream<List<Model>> getFiveList() {
try {
final response = _firebaseFirestore.collection("try").limit(5).snapshots().map((QuerySnapshot querySnapshot) =>
querySnapshot.docs.map((DocumentSnapshot documentSnapshot) =>
Model.fromJson(documentSnapshot.data())).toList());
print(response);
return response;
} catch(err) {
print(err);
return null;
}
Stream getFiveList(){
试一试{
最终响应=_firebaseFirestore.collection(“try”).limit(5.snapshots().map((QuerySnapshot QuerySnapshot)=>
querySnapshot.docs.map((DocumentSnapshot DocumentSnapshot)=>
Model.fromJson(documentSnapshot.data()).toList();
打印(回复);
返回响应;
}捕捉(错误){
打印(错误);
返回null;
}
试试这个:
for(var doc in response.documents) {
print (doc.data);
}