cloud_firestore 0.8.1+1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 100

Cloud Firestore Plugin for Flutter

A Flutter plugin to use the Cloud Firestore API.

pub package

For Flutter plugins for other Firebase products, see FlutterFire.md.

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

Recent versions (0.3.x and 0.4.x) of this plugin require extensible codec functionality that is not yet released to the beta channel of Flutter. If you're encountering issues using those versions, consider switching to the dev channel.

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 maven.google.com 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:

Firestore.instance.collection('books').document()
  .setData({ 'title': 'title', 'author': 'author' });

Binding a CollectionReference to a ListView:

class BookList extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new StreamBuilder<QuerySnapshot>(
      stream: Firestore.instance.collection('books').snapshots(),
      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
        if (!snapshot.hasData) return new Text('Loading...');
        return new ListView(
          children: snapshot.data.documents.map((DocumentSnapshot document) {
            return new ListTile(
              title: new Text(document['title']),
              subtitle: new Text(document['author']),
            );
          }).toList(),
        );
      },
    );
  }
}

Performing a query:

Firestore.instance
    .collection('talks')
    .where("topic", isEqualTo: "flutter")
    .snapshots()
    .listen((data) =>
        data.documents.forEach((doc) => print(doc["title"])));

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': postSnapshot.data['likesCount'] + 1});
  }
});

Getting Started

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

0.8.1+1

  • Bump Android dependencies to latest.

0.8.1

  • Fixed bug where updating arrays in with FieldValue always throws an Exception on Android.

0.8.0

Note: this version depends on features available in iOS SDK versions 5.5.0 or later. To update iOS SDK in existing projects run pod update Firebase/Firestore.

  • Added Firestore.enablePersistence
  • Added FieldValue with all currently supported values: arrayUnion, arrayRemove, delete and serverTimestamp.
  • Added arrayContains argument in Query.where method.

0.7.4

  • Bump Android and Firebase dependency versions.

0.7.3

  • Updated Gradle tooling to match Android Studio 3.1.2.

0.7.2

  • Fixes crash on Android if a FirebaseFirestoreException happened.

0.7.1

  • Updated iOS implementation to reflect Firebase API changes.
  • Fixed bug in Transaction.get that would fail on no data.
  • Fixed error in README.md code sample.

0.7.0+2

  • Update transactions example in README to add await.

0.7.0+1

  • Add transactions example to README.

0.7.0

  • Breaking change. snapshots is now a method instead of a getter.
  • Breaking change. setData uses named arguments instead of SetOptions.

0.6.3

  • Updated Google Play Services dependencies to version 15.0.0.

0.6.2

  • Support for BLOB data type.

0.6.1

  • Simplified podspec for Cocoapods 1.5.0, avoiding link issues in app archives.

0.6.0

  • Breaking change. Renamed 'getCollection()' to 'collection().'

0.5.1

  • Expose the Firebase app corresponding to a Firestore
  • Expose a constructor for a Firestore with a non-default Firebase app

0.5.0

  • Breaking change. Move path getter to CollectionReference
  • Add id getter to CollectionReference

0.4.0

  • Breaking change. Hide Firestore codec class from public API.
  • Adjusted Flutter SDK constraint to match Flutter release with extensible platform message codec, required already by version 0.3.1.
  • Move each class into separate files

0.3.2

  • Support for batched writes.

0.3.1

  • Add GeoPoint class
  • Allow for reading and writing DocumentReference, DateTime, and GeoPoint values from and to Documents.

0.3.0

  • Breaking change. Set SDK constraints to match the Flutter beta release.

0.2.12

  • Fix handling of null document snapshots (document not exists).
  • Add DocumentSnapshot.exists.

0.2.11

  • Fix Dart 2 type errors.

0.2.10

  • Fix Dart 2 type errors.

0.2.9

  • Relax sdk upper bound constraint to '<2.0.0' to allow 'edge' dart sdk use.

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

example/lib/main.dart

// 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:firebase_core/firebase_core.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

Future<void> main() async {
  final FirebaseApp app = await FirebaseApp.configure(
    name: 'test',
    options: const FirebaseOptions(
      googleAppID: '1:79601577497:ios:5f2bcc6ba8cecddd',
      gcmSenderID: '79601577497',
      apiKey: 'AIzaSyArgmRGfB5kiQT6CunAOmKRVKEsxKmy6YI-G72PVU',
      projectID: 'flutter-firestore',
    ),
  );
  final Firestore firestore = Firestore(app: app);

  runApp(MaterialApp(
      title: 'Firestore Example', home: MyHomePage(firestore: firestore)));
}

class MessageList extends StatelessWidget {
  MessageList({this.firestore});

  final Firestore firestore;

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<QuerySnapshot>(
      stream: firestore.collection('messages').snapshots(),
      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
        if (!snapshot.hasData) return const Text('Loading...');
        final int messageCount = snapshot.data.documents.length;
        return ListView.builder(
          itemCount: messageCount,
          itemBuilder: (_, int index) {
            final DocumentSnapshot document = snapshot.data.documents[index];
            return ListTile(
              title: Text(document['message'] ?? '<No message retrieved>'),
              subtitle: Text('Message ${index + 1} of $messageCount'),
            );
          },
        );
      },
    );
  }
}

class MyHomePage extends StatelessWidget {
  MyHomePage({this.firestore});
  final Firestore firestore;
  CollectionReference get messages => firestore.collection('messages');

  Future<Null> _addMessage() async {
    final DocumentReference document = messages.document();
    document.setData(<String, dynamic>{
      'message': 'Hello world!',
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Firestore Example'),
      ),
      body: MessageList(firestore: firestore),
      floatingActionButton: FloatingActionButton(
        onPressed: _addMessage,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  cloud_firestore: ^0.8.1+1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages 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.8.1+1 Oct 12, 2018 Go to the documentation of cloud_firestore 0.8.1+1 Download cloud_firestore 0.8.1+1 archive
0.8.1 Oct 2, 2018 Go to the documentation of cloud_firestore 0.8.1 Download cloud_firestore 0.8.1 archive
0.8.0 Sep 5, 2018 Go to the documentation of cloud_firestore 0.8.0 Download cloud_firestore 0.8.0 archive
0.7.4 Jul 23, 2018 Go to the documentation of cloud_firestore 0.7.4 Download cloud_firestore 0.7.4 archive
0.7.3 Jun 1, 2018 Go to the documentation of cloud_firestore 0.7.3 Download cloud_firestore 0.7.3 archive
0.7.2 May 15, 2018 Go to the documentation of cloud_firestore 0.7.2 Download cloud_firestore 0.7.2 archive
0.7.1 May 14, 2018 Go to the documentation of cloud_firestore 0.7.1 Download cloud_firestore 0.7.1 archive
0.7.0+2 May 7, 2018 Go to the documentation of cloud_firestore 0.7.0+2 Download cloud_firestore 0.7.0+2 archive
0.7.0+1 May 7, 2018 Go to the documentation of cloud_firestore 0.7.0+1 Download cloud_firestore 0.7.0+1 archive
0.7.0 May 7, 2018 Go to the documentation of cloud_firestore 0.7.0 Download cloud_firestore 0.7.0 archive

All 39 versions...

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

We analyzed this package on Oct 12, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4
  • Flutter: 0.9.5

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
collection ^1.14.3 1.14.11
firebase_core ^0.2.5+1 0.2.5+1
flutter 0.0.0
meta ^1.0.5 1.1.6
Transitive dependencies
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test