title: Can't get documents from firestore on flutter
body: <p>I'm trying to get documents in brews collection from firestore database.</p>
  <p>I wrote code like below but it's getting empty array.</p>
  <p>What is wrong with my code?</p>
  <p>Help me somebody who is used to flutter and firebase.</p>
  <pre><code>import 'package:cloud_firestore/cloud_firestore.dart';
  import 'package:brew_crew/models/brew.dart';
  
  class DatabaseService {
  
    final String uid;
    DatabaseService({ this.uid });
  
    // collection references
    final CollectionReference brewCollection = FirebaseFirestore.instance.collection(&quot;brews&quot;);
  
  ~~~ short cut ~~~
  
    // brew list from snapshot
    List&lt;Brew&gt; _brewListFromSnapshot(QuerySnapshot snapshot) {
      print(snapshot.docs.length); // return 0.
      // print(snapshot.docs.toString()); // here this returns [].
      return snapshot.docs.map((doc) {
        return Brew(
          name: doc.data()['name'] ?? '',
          strength: doc.data()['strength'] ?? 0,
          sugars: doc.data()['sugars'] ?? 0,
        );
      }).toList();
    }
  
    Stream&lt;List&lt;Brew&gt;&gt; get brews {
      return brewCollection.snapshots()
          .map(_brewListFromSnapshot);
    }
  }
  </code></pre>
  <p>Added the code using the stream</p>
  <p>home.dart</p>
  <pre><code>import 'package:brew_crew/screens/services/auth.dart';
  import 'package:brew_crew/screens/services/database.dart';
  import 'package:flutter/material.dart';
  import 'package:provider/provider.dart';
  import 'package:brew_crew/screens/home/brew_list.dart';
  
  class Home extends StatelessWidget {
  
    final AuthService _auth = AuthService();
  
    @override
    Widget build(BuildContext context) {
      return StreamProvider&lt;List&lt;Brew&gt;&gt;.value(
        value: DatabaseService().brews, // here using the stream.
  child: Scaffold(
  
  ~~~ short cut ~~~
  
          body: BrewList(), // here too.
        ),
      );
    }
  }
  </code></pre>
  <p>This is a file for home screen page and makes DatabaseService instance to call brews stream.</p>
  <p>This is passing brews stream as value to Provider and the value is called in BrewList instance in body.</p>
  <p>brew_list.dart</p>
  <pre><code>import 'package:brew_crew/models/brew.dart';
  import 'package:cloud_firestore/cloud_firestore.dart';
  import 'package:flutter/material.dart';
  import 'package:provider/provider.dart';
  
  class BrewList extends StatefulWidget {
    @override
    _BrewListState createState() =&gt; _BrewListState();
  }
  
  class _BrewListState extends State&lt;BrewList&gt; {
    @override
    Widget build(BuildContext context) {
      final brews = Provider.of&lt;List&lt;Brew&gt;&gt;(context);
      brews.forEach((brew) {
        print(brew.name);
        print(brew.sugars);
      });
      // print(brews.toString()); // here returns [] too.
      return Container();
    }
  }
  </code></pre>
  <p>In BrewList class, just calls Provider value.</p>
  <p>Added</p>
  <p>brew_list.dart</p>
  <pre><code>print(brews.length);
  </code></pre>
  <p>returns</p>
  <pre><code>Performing hot reload...
  Syncing files to device iPhone 8...
  flutter: 0
  Reloaded 4 of 667 libraries in 253ms.
  flutter: 0
  flutter: 0
  </code></pre>
  <p>Added</p>
  <p>I get this error when using forEach in brew_list.dart.</p>
  <pre><code>The following NoSuchMethodError was thrown building BrewList(dirty, dependencies: [_InheritedProviderScope&lt;List&lt;Brew&gt;&gt;], state: _BrewListState#eaba8):
  The method 'forEach' was called on null.
  Receiver: null
  Tried calling: forEach(Closure: (Brew) =&gt; Null)
  </code></pre>