我想在 Flutter 中从 Firestore Firebase 检索数据,但将其显示到列表视图中,我按照 youtube 上的教程进行操作。但它显示错误“状态不佳:DocumentSnapshotPlatform 中不存在字段”。我不知道如何修复它。任何人都可以帮助我如何解决它?谢谢!!
Widget build(BuildContext context) {
return Scaffold(
body: StreamBuilder(
stream: FirebaseFirestore.instance.collection('TransactionExpense').snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasData) {
return ListView(
children: snapshot.data.docs.map((document) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(children: [
SizedBox(width: 6,),
Text(document['category'],style: TextStyle(fontSize: 16,
color: primary,
fontWeight: FontWeight.w600
),),
],
),
SizedBox(height: 10,),
Row(children: [
SizedBox(width: 6,),
Text(document['dates'],style: TextStyle(fontSize: 16,
color: primary,
fontWeight: FontWeight.w600
),),
SizedBox(width: 200,),
SizedBox(width: 6,),
Text(document['amount'],style: TextStyle(fontSize: 16,
color: primary,
fontWeight: FontWeight.w600
),),
],
),
SizedBox(height: 8,),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
GestureDetector(
onTap: (){
//_showDeleteDialog(transactionexpense: transactionexpense);
},
child: Row(
children: [
Icon(Icons.delete_forever_outlined,
color: Colors.red,
),
SizedBox(width: 6,),
Text('Delete', style: TextStyle(fontSize: 16,
color: Colors.red,
fontWeight: FontWeight.w600
), ),
],
),
)
],
)
],
),
);
}).toList(),
);
}
return Center(
child: CircularProgressIndicator(),
);
}
),
);
}