Home > front end >  Bad state: field does not exist within the DocumentSnapshotPlatform in Flutter
Bad state: field does not exist within the DocumentSnapshotPlatform in Flutter

Time:10-04

I hope you're all having a swell day! I'm getting the following error whenever I search for a user in the search bar of my Messenger App in Flutter:

    ======== Exception caught by widgets library =======================================================
The following StateError was thrown building:
Bad state: field does not exist within the DocumentSnapshotPlatform

When the exception was thrown, this was the stack: 
#0      DocumentSnapshotPlatform.get._findKeyValueInMap (package:cloud_firestore_platform_interface/src/platform_interface/platform_interface_document_snapshot.dart:87:7)
#1      DocumentSnapshotPlatform.get._findComponent (package:cloud_firestore_platform_interface/src/platform_interface/platform_interface_document_snapshot.dart:105:23)
#2      DocumentSnapshotPlatform.get (package:cloud_firestore_platform_interface/src/platform_interface/platform_interface_document_snapshot.dart:121:12)
#3      _JsonDocumentSnapshot.get (package:cloud_firestore/src/document_snapshot.dart:92:48)
#4      _JsonDocumentSnapshot.[] (package:cloud_firestore/src/document_snapshot.dart:96:40)
#5      _HomeState.searchUsersList.<anonymous closure>.<anonymous closure> (package:messenger_clone/views/home.dart:113:37)
#6      SliverChildBuilderDelegate.build (package:flutter/src/widgets/sliver.dart:456:22)
#7      SliverMultiBoxAdaptorElement._build (package:flutter/src/widgets/sliver.dart:1214:28)
#8      SliverMultiBoxAdaptorElement.performRebuild.processElement (package:flutter/src/widgets/sliver.dart:1147:67)
#9      Iterable.forEach (dart:core/iterable.dart:279:35)
#10     SliverMultiBoxAdaptorElement.performRebuild (package:flutter/src/widgets/sliver.dart:1191:24)
#11     SliverMultiBoxAdaptorElement.update (package:flutter/src/widgets/sliver.dart:1125:7)
#12     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#13     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#14     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#15     ProxyElement.update (package:flutter/src/widgets/framework.dart:5020:5)
#16     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#17     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#18     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#19     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5700:32)
#20     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6356:17)
#21     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#22     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#23     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#24     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#25     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#26     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#27     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#28     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#29     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#30     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#31     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
#32     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#33     StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
#34     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#35     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#36     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#37     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#38     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#39     ProxyElement.update (package:flutter/src/widgets/framework.dart:5020:5)
#40     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#41     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#42     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#43     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#44     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#45     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#46     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#47     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#48     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#49     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#50     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#51     StatelessElement.update (package:flutter/src/widgets/framework.dart:4746:5)
#52     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#53     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#54     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
#55     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#56     StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
#57     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#58     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#59     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
#60     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#61     StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
#62     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#63     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#64     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#65     StatelessElement.update (package:flutter/src/widgets/framework.dart:4746:5)
#66     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#67     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#68     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
#69     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#70     StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
#71     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#72     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5700:32)
#73     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6356:17)
#74     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#75     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#76     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#77     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#78     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#79     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#80     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#81     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#82     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#83     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#84     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#85     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#86     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
#87     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#88     StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
#89     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#90     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#91     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#92     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#93     Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#94     ProxyElement.update (package:flutter/src/widgets/framework.dart:5020:5)
#95     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#96     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#97     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#98     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#99     Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#100    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#101    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#102    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#103    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#104    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#105    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#106    StatelessElement.update (package:flutter/src/widgets/framework.dart:4746:5)
#107    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#108    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#109    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
#110    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#111    StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
#112    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#113    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#114    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
#115    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#116    StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
#117    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#118    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#119    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#120    ProxyElement.update (package:flutter/src/widgets/framework.dart:5020:5)
#121    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#122    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#123    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#124    StatelessElement.update (package:flutter/src/widgets/framework.dart:4746:5)
#125    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#126    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#127    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#128    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#129    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#130    StatelessElement.update (package:flutter/src/widgets/framework.dart:4746:5)
#131    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#132    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#133    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#134    StatelessElement.update (package:flutter/src/widgets/framework.dart:4746:5)
#135    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#136    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#137    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#138    ProxyElement.update (package:flutter/src/widgets/framework.dart:5020:5)
#139    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#140    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#141    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#142    ProxyElement.update (package:flutter/src/widgets/framework.dart:5020:5)
#143    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#144    RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5700:32)
#145    MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6356:17)
#146    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#147    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#148    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
#149    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#150    StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
#151    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#152    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#153    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#154    ProxyElement.update (package:flutter/src/widgets/framework.dart:5020:5)
#155    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#156    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#157    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
#158    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#159    StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
#160    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#161    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#162    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#163    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#164    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#165    StatelessElement.update (package:flutter/src/widgets/framework.dart:4746:5)
#166    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#167    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6202:14)
#168    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#169    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#170    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
#171    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#172    StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
#173    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#174    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#175    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
#176    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#177    StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
#178    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#179    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#180    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#181    ProxyElement.update (package:flutter/src/widgets/framework.dart:5020:5)
#182    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#183    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#184    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#185    StatelessElement.update (package:flutter/src/widgets/framework.dart:4746:5)
#186    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#187    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#188    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
#189    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#190    StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
#191    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#192    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#193    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#194    ProxyElement.update (package:flutter/src/widgets/framework.dart:5020:5)
#195    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#196    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#197    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
#198    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#199    StatefulElement.update (package:flutter/src/widgets/framework.dart:4872:5)
#200    Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
#201    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4690:16)
#202    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4840:11)
#203    Element.rebuild (package:flutter/src/widgets/framework.dart:4355:5)
#204    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2620:33)
#205    WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:882:21)
#206    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:319:5)
#207    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1143:15)
#208    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1080:9)
#209    SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:996:5)
#213    _invoke (dart:ui/hooks.dart:166:10)
#214    PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:270:5)
#215    _drawFrame (dart:ui/hooks.dart:129:31)
(elided 3 frames from dart:async)
====================================================================================================

This is the piece of code that the error narrows down to:

Widget searchUsersList() {
    return StreamBuilder(
      stream: usersStream,
      builder: (context, snapshot) {
        return snapshot.hasData
            ? ListView.builder(
                itemCount: snapshot.data.docs.length,
                shrinkWrap: true,
                itemBuilder: (context, index) {
                  DocumentSnapshot ds = snapshot.data.docs[index];
                  return searchListUserTile(
                      profileUrl: ds["imgUrl"],
                      name: ds["name"],
                      email: ds["email"],
                      username: ds["username"]);
                },
              )
            : Center(
                child: CircularProgressIndicator(),
              );
      },
    );
  }

I've double checked and the field names are correct, so I don't think it's that. So what is the issue here? If someone can help me fix it, it'd help me a lot! Thanks in advance.

CodePudding user response:

try to add this line

if(snapshot.connectionState==ConnectionState.done)

before the listview

CodePudding user response:

DocumentSnapshot does not directly contain the data. You can access data like ds.data()["imgUrl"] etc.

  • Related