cloud_firestore 0.2.8

  • Example
  • Installing
  • Versions
  • 50

Cloud Firestore Plugin for Flutter #

A Flutter plugin to use the Cloud Firestore API.

pub package

For Flutter plugins for other Firebase products, see

Note: This plugin is still under development, and some APIs might not be available yet. Feedback and Pull Requests are most welcome!

Setup #

To use this plugin:

  1. Using the Firebase Console, add an Android app to your project: Follow the assistant, download the generated google-services.json file and place it inside android/app. Next, 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.
  2. Using the Firebase Console, add an iOS app to your project: Follow the assistant, download the generated GoogleService-Info.plist file, open ios/Runner.xcworkspace with Xcode, and within Xcode place the file inside ios/Runner. Don't follow the steps named "Add Firebase SDK" and "Add initialization code" in the Firebase assistant.
  3. Add cloud_firestore as a dependency in your pubspec.yaml file.

Usage #

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 new StreamBuilder(
      stream: Firestore.instance.collection('books').snapshots,
      builder: (context, snapshot) {
        if (!snapshot.hasData) return new Text('Loading...');
        return new ListView(
          children: {
            return new ListTile(
              title: new Text(document['title']),
              subtitle: new Text(document['author']),

Getting Started #

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

0.2.8 #

  • Support for Query.getDocuments

0.2.7 #

  • Add transaction support.

0.2.6 #

  • Build fixes for iOS
  • Null checking in newly added Query methods

0.2.5 #

  • Query can now have more than one orderBy field.
  • startAt, startAfter, endAt, and endBefore support
  • limit support

0.2.4 #

  • Support for DocumentReference.documentID
  • Support for CollectionReference.add

0.2.3 #

  • Simplified and upgraded Android project template to Android SDK 27.
  • Updated package description.

0.2.2 #

  • Add get to DocumentReference.

0.2.1 #

  • Fix bug on Android where removeListener is sometimes called without a handle

0.2.0 #

  • Breaking change. Upgraded to Gradle 4.1 and Android Studio Gradle plugin 3.0.1. Older Flutter projects need to upgrade their Gradle setup as well in order to use this version of the plugin. Instructions can be found here.
  • Relaxed GMS dependency to [11.4.0,12.0[

0.1.2 #

  • Support for DocumentReference update and merge writes
  • Suppress unchecked warnings and package name warnings on Android

0.1.1 #

  • Added FLT prefix to iOS types.

0.1.0 #

  • Added reference to DocumentSnapshot
  • Breaking: removed path from DocumentSnapshot
  • Additional test coverage for reading collections and documents
  • Fixed typo in DocumentChange documentation

0.0.6 #

  • Support for getCollection

0.0.5 #

  • Support isNull filtering in Query.where
  • Fixed DocumentChange.oldIndex and DocumentChange.newIndex to be signed integers (iOS)

0.0.4 #

  • Support for where clauses
  • Support for deletion

0.0.3 #

  • Renamed package to cloud_firestore

0.0.2 #

  • Add path property to DocumentSnapshot

0.0.1+1 #

  • Update project homepage

0.0.1 #

  • Initial Release


// Copyright 2017, the Chromium project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(new MaterialApp(title: 'Firestore Example', home: new MyHomePage()));

class BookList extends StatelessWidget {
  Widget build(BuildContext context) {
    return new StreamBuilder<QuerySnapshot>(
      stream: Firestore.instance.collection('books').snapshots,
      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
        if (!snapshot.hasData) return const Text('Loading...');
        return new ListView(
          children: document) {
            return new ListTile(
              title: new Text(document['message']),

class MyHomePage extends StatelessWidget {
  CollectionReference get messages => Firestore.instance.collection('messages');

  Future<Null> _addMessage() async {
//    Firestore.instance
//        .collection('books')
//        .document()
//        .setData(<String, String>{'message': 'Hello world!'});
    final TransactionHandler transactionHandler = (Transaction tx) async {
      print('handler on dart side');
      final DocumentSnapshot documentSnapshot = await tx

      await tx.update(documentSnapshot.reference, <String, dynamic>{
        'message':['message'] + ' good'
      return <String, dynamic>{'val': 1};
        .runTransaction(transactionHandler, timeout: new Duration(seconds: 10))
        .then((Map<String, dynamic> result) {
      print('transaction is complete');
    }).catchError((PlatformException e) {
      print('dart side error message: ' + e.message);

  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: const Text('Firestore Example'),
      body: new BookList(),
      floatingActionButton: new FloatingActionButton(
        onPressed: _addMessage,
        tooltip: 'Increment',
        child: new Icon(Icons.add),

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  cloud_firestore: ^0.2.8

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:cloud_firestore/cloud_firestore.dart';
Version Uploaded Documentation Archive
0.12.5+2 Jun 19, 2019 Go to the documentation of cloud_firestore 0.12.5+2 Download cloud_firestore 0.12.5+2 archive
0.12.5+1 Jun 15, 2019 Go to the documentation of cloud_firestore 0.12.5+1 Download cloud_firestore 0.12.5+1 archive
0.12.5 Jun 10, 2019 Go to the documentation of cloud_firestore 0.12.5 Download cloud_firestore 0.12.5 archive
0.12.3 Jun 6, 2019 Go to the documentation of cloud_firestore 0.12.3 Download cloud_firestore 0.12.3 archive
0.12.2 Jun 4, 2019 Go to the documentation of cloud_firestore 0.12.2 Download cloud_firestore 0.12.2 archive
0.12.1 May 30, 2019 Go to the documentation of cloud_firestore 0.12.1 Download cloud_firestore 0.12.1 archive
0.12.0+2 May 30, 2019 Go to the documentation of cloud_firestore 0.12.0+2 Download cloud_firestore 0.12.0+2 archive
0.12.0+1 May 29, 2019 Go to the documentation of cloud_firestore 0.12.0+1 Download cloud_firestore 0.12.0+1 archive
0.12.0 May 27, 2019 Go to the documentation of cloud_firestore 0.12.0 Download cloud_firestore 0.12.0 archive
0.11.0+2 May 14, 2019 Go to the documentation of cloud_firestore 0.11.0+2 Download cloud_firestore 0.11.0+2 archive

All 75 versions...

Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0-dev.infinity