How to get all data from a Firestore collection in flutter?

3 min read
get all data from a Firestore collection in flutter
get all data from a Firestore collection in flutter

Earlier we have been through articles related to firebase like How to Delete All Documents In a Collection In FireStore With Flutter? and many more. So today, in this article, we will learn about How to get all data from a Firestore collection in flutter.

How to get all data from a Firestore collection in flutter?

Call the getDocs() function, then use the build function, then print all the document IDs in the console. Here is how you do it!

Future getDocs() async {
  QuerySnapshot querySnapshot = await Firestore.instance.collection("collection").getDocuments();
  for (int i = 0; i < querySnapshot.documents.length; i++) {
    var a = querySnapshot.documents[i];

Get all data from the collection that you found working, without using deprecated methods.

CollectionReference _collectionRef =

Future<void> getData() async {
    // Get docs from collection reference
    QuerySnapshot querySnapshot = await _collectionRef.get();

    // Get data from docs and convert map to List
    final allData = =>;


Using StreamBuilder as shown below:

import 'package:flutter/material.dart';
import 'package:firebase_firestore/firebase_firestore.dart';

class ExpenseList extends StatelessWidget {
  Widget build(BuildContext context) {
    return new StreamBuilder<QuerySnapshot>(
        stream: Firestore.instance.collection("expenses").snapshots,
        builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
          if (!snapshot.hasData) return new Text("There is no expense");
          return new ListView(children: getExpenseItems(snapshot));

  getExpenseItems(AsyncSnapshot<QuerySnapshot> snapshot) {
        .map((doc) => new ListTile(title: new Text(doc["name"]), subtitle: new Text(doc["amount"].toString())))

User can also give try the following code and check the cloud_firestore plugin for flutter :

QuerySnapshot snap = await 

snap.documents.forEach((document) {


Thanks for being with us on a聽Flutter Journey!!!

If you are still having doubts about Flutter Development, Let us know!! We would love to assist you 馃檪

So in this article, we have Learned How to get all data from a Firestore collection in flutter!!

Keep聽Learning聽!!! Keep聽Fluttering !!! Stay Connected !!!

Also, check out the complete step-by-step guide on Implement Staggered GridView In Flutter!

Don’t forget to drop your valuable feedback in the comments right below 馃檪

Flutter Agency聽is our portal Platform dedicated to Flutter Technology and聽Flutter Developers. The portal is full of cool resources from Flutter like聽Flutter Widget聽Guide,聽Flutter Projects,聽Code libs聽and etc.

Flutter Agency聽is one of the most popular online portals dedicated to聽Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge of聽Flutter.

Leave a Reply