Cloud Firestore Plugin for Flutter

A Flutter plugin to use the Cloud Firestore API.

pub package

For Flutter plugins for other Firebase products, see


To use this plugin:

  1. Add cloud_firestore as a dependency in your pubspec.yaml file.


  1. Using the Firebase Console, add an Android app to your project.
  2. Follow the assistant, and download the generated google-services.json file and place it inside android/app.
  3. Modify the android/build.gradle file and the android/app/build.gradle file to add the Google services plugin as described by the Firebase assistant. Ensure that your android/build.gradle file contains the as described here.


  1. Using the Firebase Console, add an iOS app to your project.
  2. Follow the assistant, download the generated GoogleService-Info.plist file. Do NOT follow the steps named "Add Firebase SDK" and "Add initialization code" in the Firebase assistant.
  3. Open ios/Runner.xcworkspace with Xcode, and within Xcode place the GoogleService-Info.plist file inside ios/Runner.


In addition to the cloud_firestore dependency, you'll need to modify the web/index.html of your app following the Firebase setup instructions:

Read more in the cloud_firestore_web README.


import 'package:cloud_firestore/cloud_firestore.dart';

Adding a new DocumentReference:

  .setData({ 'title': 'title', 'author': 'author' });

Binding a CollectionReference to a ListView:

class BookList extends StatelessWidget {
  Widget build(BuildContext context) {
    return StreamBuilder<QuerySnapshot>(
      stream: Firestore.instance.collection('books').snapshots(),
      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
        if (snapshot.hasError)
          return new Text('Error: ${snapshot.error}');
        switch (snapshot.connectionState) {
          case ConnectionState.waiting: return new Text('Loading...');
            return new ListView(
              children: document) {
                return new ListTile(
                  title: new Text(document['title']),
                  subtitle: new Text(document['author']),

Performing a query:

    .where("topic", isEqualTo: "flutter")
    .listen((data) =>
        data.documents.forEach((doc) => print(doc["title"])));

Get a specific document:

        .then((DocumentSnapshot ds) {
      // use ds as a snapshot

Running a transaction:

final DocumentReference postRef = Firestore.instance.document('posts/123');
Firestore.instance.runTransaction((Transaction tx) async {
  DocumentSnapshot postSnapshot = await tx.get(postRef);
  if (postSnapshot.exists) {
    await tx.update(postRef, <String, dynamic>{'likesCount':['likesCount'] + 1});

Getting Started

See the example directory for a complete sample app using Cloud Firestore.

Issues and feedback

Please file Flutterfire specific issues, bugs, or feature requests in our issue tracker.

Plugin issues that are not specific to Flutterfire can be filed in the Flutter issue tracker.

To contribute a change to this plugin, please review our contribution guide, and send a pull request.