title: Flutter - NoSuchMethodError: The method '[]' was called on null
body: <p>I am encountering an error while trying to fetch data from Firestore using FutureBuilder. If a user logs in and I print (snapshot.data), I get a correct snapshot been pulled from the firestore:</p>
  
  <pre><code>flutter: FirebaseUser({displayName: null, providerId: Firebase, uid: UFubdB2xPCTUu8ESgQikOr9WOe52, phoneNumber: null, isEmailVerified: false, providerData: [{email: titi@momo.com, providerId: password, photoUrl: null, displayName: null, uid: titi@momo.com, phoneNumber: null}], email: titi@momo.com, photoUrl: null, lastSignInTimestamp: 1576367769805, isAnonymous: false, creationTimestamp: 1576367424402})
  </code></pre>
  
  <p>However if I navigate to the Feed screen, it throws an exception when i print (snapshot.data['email'])</p>
  
  <pre><code>flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
  flutter: The following NoSuchMethodError was thrown building FutureBuilder&lt;DocumentSnapshot&gt;(dirty, state:
  flutter: _FutureBuilderState&lt;DocumentSnapshot&gt;#5d856):
  flutter: The method '[]' was called on null.
  flutter: Receiver: null
  flutter: Tried calling: []("email")
  flutter:
  flutter: The relevant error-causing widget was:
  flutter:   FutureBuilder&lt;DocumentSnapshot&gt; file:///Users/momo/Desktop/combine/lib/screens/feed.dart:23:13
  flutter:
  flutter: When the exception was thrown, this was the stack:
  flutter: #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
  flutter: #1      _FeedState.build.&lt;anonymous closure&gt; (package:combine/screens/feed.dart:26:30)
  flutter: #2      _FutureBuilderState.build (package:flutter/src/widgets/async.dart)
  flutter: #3      StatefulElement.build (package:flutter/src/widgets/framework.dart:4334:27)
  flutter: #4      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4223:15)
  flutter: #5      Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #6      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #7      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
  flutter: #8      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #9      Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #10     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #11     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #12     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #13     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #14     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #15     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #16     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #17     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #18     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #19     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #20     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #21     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #22     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #23     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #24     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #25     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #26     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #27     ParentDataElement.mount (package:flutter/src/widgets/framework.dart:4617:11)
  flutter: #28     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #29     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5551:32)
  flutter: #30     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #31     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #32     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #33     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #34     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #35     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
  flutter: #36     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #37     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #38     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #39     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #40     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #41     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #42     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #43     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #44     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #45     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #46     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #47     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #48     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
  flutter: #49     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #50     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #51     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #52     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
  flutter: #53     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #54     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #55     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #56     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #57     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #58     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #59     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #60     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #61     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
  flutter: #62     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #63     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #64     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #65     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #66     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #67     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
  flutter: #68     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #69     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #70     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #71     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #72     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #73     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #74     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
  flutter: #75     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #76     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #77     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #78     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #79     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #80     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #81     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #82     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #83     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #84     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #85     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #86     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #87     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #88     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #89     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #90     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #91     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #92     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #93     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
  flutter: #94     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #95     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #96     Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #97     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #98     Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #99     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #100    StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
  flutter: #101    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #102    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #103    Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #104    SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
  flutter: #105    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #106    Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #107    SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
  flutter: #108    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #109    Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #110    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #111    Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #112    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #113    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #114    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #115    Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #116    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #117    Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #118    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #119    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #120    ParentDataElement.mount (package:flutter/src/widgets/framework.dart:4617:11)
  flutter: #121    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #122    Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #123    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #124    Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #125    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #126    StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
  flutter: #127    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #128    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #129    Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #130    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
  flutter: #131    Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
  flutter: #132    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
  flutter: #133    ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
  flutter: #134    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
  flutter: #135    Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
  flutter: #136    SliverMultiBoxAdaptorElement.updateChild (package:flutter/src/widgets/sliver.dart:1288:36)
  flutter: #137    SliverMultiBoxAdaptorElement.createChild.&lt;anonymous closure&gt; (package:flutter/src/widgets/sliver.dart:1273:20)
  flutter: #138    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2412:19)
  flutter: #139    SliverMultiBoxAdaptorElement.createChild (package:flutter/src/widgets/sliver.dart:1266:11)
  flutter: #140    RenderSliverMultiBoxAdaptor._createOrObtainChild.&lt;anonymous closure&gt; (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:354:23)
  flutter: #141    RenderObject.invokeLayoutCallback.&lt;anonymous closure&gt; (package:flutter/src/rendering/object.dart:1823:58)
  flutter: #142    PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:875:15)
  flutter: #143    RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:1823:13)
  flutter: #144    RenderSliverMultiBoxAdaptor._createOrObtainChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:343:5)
  flutter: #145    RenderSliverMultiBoxAdaptor.insertAndLayoutChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:489:5)
  flutter: #146    RenderSliverFixedExtentBoxAdaptor.performLayout (package:flutter/src/rendering/sliver_fixed_extent_list.dart:255:17)
  flutter: #147    RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
  flutter: #148    RenderSliverEdgeInsetsPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:134:11)
  flutter: #149    _RenderSliverFractionalPadding.performLayout (package:flutter/src/widgets/sliver.dart:1165:11)
  flutter: #150    RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
  flutter: #151    RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:410:13)
  flutter: #152    RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1367:12)
  flutter: #153    RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1285:20)
  flutter: #154    RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1584:7)
  flutter: #155    PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:844:18)
  flutter: #156    RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:344:19)
  flutter: #157    WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:774:13)
  flutter: #158    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)
  flutter: #159    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1102:15)
  flutter: #160    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1041:9)
  flutter: #161    SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:957:5)
  flutter: #165    _invoke (dart:ui/hooks.dart:259:10)
  flutter: #166    _drawFrame (dart:ui/hooks.dart:217:3)
  flutter: (elided 3 frames from package dart:async)
  flutter:
  flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
  flutter: Another exception was thrown: NoSuchMethodError: The method '[]' was called on null.
  flutter: titi@momo.com
  
  </code></pre>
  
  <p>However, if i print only the (snapshot.data) while on the Feed screen, it throws up a null before getting the instance.</p>
  
  <pre><code>flutter: null
  flutter: null
  flutter: Instance of 'DocumentSnapshot'
  </code></pre>
  
  <p><strong>Navigation from Main Page</strong> </p>
  
  <pre><code>class MyApp extends StatelessWidget {
    Widget _getScreenId() {
      return StreamBuilder&lt;FirebaseUser&gt;(
          stream: FirebaseAuth.instance.onAuthStateChanged,
          builder: (BuildContext context, snapshot) {
            if (snapshot.hasData) {
              print(snapshot.data);
              return Landing(userId: snapshot.data.uid);
            } else {
              return Login();
            }
          });
    }
  </code></pre>
  
  <p><strong>Navigation to Feed screen from Landing</strong></p>
  
  <pre><code>children: &lt;Widget&gt;[
            Home(),
            Feed(userId: widget.userId),
            Profile(),
          ],
  </code></pre>
  
  <p><strong>Feed Screen</strong></p>
  
  <pre><code>class Feed extends StatefulWidget {
    final String userId;
  
    Feed({this.userId});
  
    @override
    _FeedState createState() =&gt; _FeedState();
  }
  
  class _FeedState extends State&lt;Feed&gt; {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.white,
          elevation: 1,
          title: Text('feed screen'),
        ),
        backgroundColor: Colors.white,
        body: FutureBuilder(
          future: usersRef.document(widget.userId).get(),
          builder: (BuildContext context, AsyncSnapshot snapshot) {
            print(snapshot.data['email']);
            return Padding(
              padding: const EdgeInsets.only(top: 70, left: 20, right: 20),
              child: Column(
                children: &lt;Widget&gt;[
                  Text('MeandYou')
                ],
              ),
            );
          },
        ),
      );
    }
  }
  </code></pre>
  
  <p><strong>usersRef</strong></p>
  
  <pre><code>final usersRef = _firestore.collection('users');
  </code></pre>
  
  <p><strong>User Model</strong></p>
  
  <pre><code>User(
        {this.id,
        this.email,
        this.password,
        this.fullname,
        this.username,
        this.mobile,
        this.profileImgUrl,
        this.bio});
  
    factory User.fromDoc(DocumentSnapshot doc) {
      return User(
        id: doc.documentID,
        email: doc['email'],
        fullname: doc['fullname'],
        username: doc['username'],
        mobile: doc['mobile'],
        profileImgUrl: doc['profileImgUrl'],
        bio: doc['bio'] ?? ''
      );
    }
  </code></pre>
  
  <p>I have tried several options and I would appreciate some help</p>