Streambuilder的Flutter DropdownMenuItem问题

时间:2019-02-23 22:03:46

标签: flutter google-cloud-firestore

我是新手,所以请告诉我在指定详细信息时是否有误。我正在尝试显示一个下拉列表,供用户选择他/她居住的地区。地区名称以及其他详细信息存储在数据库中。我正在尝试创建一个下拉列表,并使用streambuilder从数据库中检索要显示的DropdownMenuItem。 这些是错误日志和代码:-

    I/flutter (17707): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (17707): The following NoSuchMethodError was thrown building StreamBuilder<QuerySnapshot>(dirty, state:
I/flutter (17707): _StreamBuilderBaseState<QuerySnapshot, AsyncSnapshot<QuerySnapshot>>#206f9):
I/flutter (17707): The getter 'value' was called on null.
I/flutter (17707): Receiver: null
I/flutter (17707): Tried calling: value
I/flutter (17707): 
I/flutter (17707): When the exception was thrown, this was the stack:
I/flutter (17707): #0      Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
I/flutter (17707): #1      new DropdownButton.<anonymous closure> (package:flutter/src/material/dropdown.dart:514:96)
I/flutter (17707): #2      WhereIterator.moveNext (dart:_internal/iterable.dart:439:11)
I/flutter (17707): #3      Iterable.length (dart:core/iterable.dart:423:15)
I/flutter (17707): #4      new DropdownButton (package:flutter/src/material/dropdown.dart:514:112)
I/flutter (17707): #5      _CreateState.test.<anonymous closure> (package:agripreneur/groups/create.dart:71:26)
I/flutter (17707): #6      StreamBuilder.build (package:flutter/src/widgets/async.dart:423:74)
I/flutter (17707): #7      _StreamBuilderBaseState.build (package:flutter/src/widgets/async.dart:125:48)
I/flutter (17707): #8      StatefulElement.build (package:flutter/src/widgets/framework.dart:3809:27)
I/flutter (17707): #9      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3721:15)
I/flutter (17707): #10     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #11     StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
I/flutter (17707): #12     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #13     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #14     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #15     StatelessElement.update (package:flutter/src/widgets/framework.dart:3781:5)
I/flutter (17707): #16     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #17     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4585:32)
I/flutter (17707): #18     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4975:17)
I/flutter (17707): #19     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #20     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #21     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #22     ProxyElement.update (package:flutter/src/widgets/framework.dart:3990:5)
I/flutter (17707): #23     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #24     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #25     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #26     StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
I/flutter (17707): #27     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #28     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #29     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #30     StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
I/flutter (17707): #31     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #32     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #33     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #34     ProxyElement.update (package:flutter/src/widgets/framework.dart:3990:5)
I/flutter (17707): #35     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #36     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #37     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #38     StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
I/flutter (17707): #39     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #40     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
I/flutter (17707): #41     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #42     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #43     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #44     StatelessElement.update (package:flutter/src/widgets/framework.dart:3781:5)
I/flutter (17707): #45     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #46     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
I/flutter (17707): #47     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #48     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #49     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #50     StatelessElement.update (package:flutter/src/widgets/framework.dart:3781:5)
I/flutter (17707): #51     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #52     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
I/flutter (17707): #53     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #54     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #55     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #56     StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
I/flutter (17707): #57     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #58     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #59     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #60     StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
I/flutter (17707): #61     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #62     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
I/flutter (17707): #63     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #64     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #65     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #66     StatelessElement.update (package:flutter/src/widgets/framework.dart:3781:5)
I/flutter (17707): #67     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #68     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
I/flutter (17707): #69     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #70     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #71     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #72     StatelessElement.update (package:flutter/src/widgets/framework.dart:3781:5)
I/flutter (17707): #73     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #74     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #75     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #76     ProxyElement.update (package:flutter/src/widgets/framework.dart:3990:5)
I/flutter (17707): #77     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #78     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #79     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #80     ProxyElement.update (package:flutter/src/widgets/framework.dart:3990:5)
I/flutter (17707): #81     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #82     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4585:32)
I/flutter (17707): #83     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4975:17)
I/flutter (17707): #84     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #85     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #86     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #87     StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
I/flutter (17707): #88     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #89     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #90     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #91     ProxyElement.update (package:flutter/src/widgets/framework.dart:3990:5)
I/flutter (17707): #92     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #93     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #94     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #95     StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
I/flutter (17707): #96     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #97     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
I/flutter (17707): #98     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #99     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #100    Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #101    StatelessElement.update (package:flutter/src/widgets/framework.dart:3781:5)
I/flutter (17707): #102    Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #103    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
I/flutter (17707): #104    Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #105    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): #106    Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (17707): #107    StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
I/flutter (17707): #108    Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (17707): #109    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (17707): Another exception was thrown: NoSuchMethodError: The getter 'value' was called on null.

new StreamBuilder<QuerySnapshot>(
      stream: Firestore.instance.collection("location_details").where('state', isEqualTo: 'Maharashtra').snapshots(),
      builder: (context,snapshot) {

        if (!snapshot.hasData) return new Text("Please wait");
        else
          return new DropdownButton(
            items: snapshot.data.documents.map((document) {
              for(int i = 0; i < document['district'].length; i++){
                print(i);
                print(document['district'][i]);
                new DropdownMenuItem(
                  value: document['district'][i],
                  child: new Text(document['district'][i]),
                ).build(context);
                i+=1;
              }
            }
            ).toList(),

            onChanged: (val){
              dist = val;
            },
            hint: new Text("DISTRICT"),
            style: TextStyle(color: Colors.black),
          );
      }
  ),

0 个答案:

没有答案