英文:
StateError (Bad state: field does not exist within the DocumentSnapshotPlatform) on flutter
问题
I'm new to flutter. I have a problem that I can't get over. I'm getting 'StateError (Bad state: field does not exist within the DocumentSnapshotPlatform)'.
class Recipes extends StatelessWidget {
CollectionReference recipes = FirebaseFirestore.instance.collection(emailadresi);
Widget build(BuildContext context) {
...
...
child: StreamBuilder(
stream: recipes.snapshots(),
builder: (context, snapshot) {
final docs = snapshot.data?.docs;
final user = FirebaseAuth.instance.currentUser;
if (snapshot.hasError) {
return Text('Something went wrong');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Text("Loading");
}
return Scrollbar(
child: ListView.builder(
physics: ClampingScrollPhysics(),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: docs?.length,
itemBuilder: (context, index) {
return Container(
height: 100,
padding: EdgeInsets.only(top: 2),
child: Card(
color: Color.fromARGB(198, 243, 240, 51),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: ListTile(
leading: Image.asset(
"lib/assets/logo_ust.png",
height: 40,
width: 60,
),
title: Text(docs?[index]['Aidiyet']),
subtitle: Text(docs?[index]['Durum']),
),
),
);
},
),
);
}),
}
}
I could not embed most of the things written on the internet into my code.
英文:
I'm new to flutter. I have a problem that I can't get over. I'm getting 'StateError (Bad state: field does not exist within the DocumentSnapshotPlatform)'.
`class Recipes extends StatelessWidget {
CollectionReference recipes = FirebaseFirestore.instance.collection(emailadresi);
Widget build(BuildContext context) {
.....
.....
.....
child: StreamBuilder(
stream: recipes.snapshots(),
builder: (context,snapshot){
final docs = snapshot.data?.docs;
final user = FirebaseAuth.instance.currentUser;
if (snapshot.hasError) {
return Text('Something went wrong');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Text("Loading");
}
return Scrollbar(
child: ListView.builder(
physics: ClampingScrollPhysics(),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount:docs?.length,
itemBuilder: (context,index){
return Container(
height: 100,
padding: EdgeInsets.only(top: 2),
child: Card(
color: Color.fromARGB(198, 243, 240, 51),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child:ListTile(
leading: Image.asset(
"lib/assets/logo_ust.png",
height: 40,
width: 60,
),
title: Text(docs?[index]['Aidiyet']),
subtitle: Text(docs?[index]['Durum']),
)));
},
)
);}),
`
I could not embed most of the things written on the internet into my code.
答案1
得分: 0
'StateError (Bad state: field does not exist within the DocumentSnapshotPlatform)'.
这个错误简单地表示您正在尝试访问的文档字段不存在。
错误出现在以下代码行:
title: Text(docs?[index]['Aidiyet']),
subtitle: Text(docs?[index]['Durum']),
请检查Firebase Firestore上的文档,确保给定的字段 'Aidiyet' 和 'Durum' 是否存在!
同时,检查您的查询 'FirebaseFirestore.instance.collection(emailadresi);' 是否正确,并且是否提供所需的输出。
英文:
'StateError (Bad state: field does not exist within the DocumentSnapshotPlatform)'.
The error simply indicates that the Document field which you are trying to access doesn't exist.
The error exists at this line of code:
title: Text(docs?[index]['Aidiyet']),
subtitle: Text(docs?[index]['Durum']),
Check the Document on firebase firestore that if the given fields 'Aidiyet' and 'Durum' exist or not!
Also check if your query ' FirebaseFirestore.instance.collection(emailadresi);' is correct and providing the required output.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论