StateError (Bad state: field does not exist within the DocumentSnapshotPlatform) on flutter

huangapple go评论45阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年5月6日 23:22:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76189675.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定