A Flutter plugin to use the Cloud Firestore API.
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.
To use this plugin:
android/build.gradle
file contains the
maven.google.com
as described here.cloud_firestore
as a dependency in your pubspec.yaml file.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 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...');
default:
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});
}
});
See the example
directory for a complete sample app using Cloud Firestore.
Firestore.settings
Timestamp
classFieldValue
always throws an Exception on Android.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
.
Firestore.enablePersistence
FieldValue
with all currently supported values: arrayUnion
, arrayRemove
, delete
and
serverTimestamp
.arrayContains
argument in Query.where
method.await
.snapshots
is now a method instead of a getter.setData
uses named arguments instead of SetOptions
.null
document snapshots (document not exists).DocumentSnapshot.exists
.get
to DocumentReference.DocumentReference
update and merge writesisNull
filtering in Query.where
DocumentChange.oldIndex
and DocumentChange.newIndex
to be signed
integers (iOS)example/README.md
Demonstrates how to use the firestore plugin.
For help getting started with Flutter, view our online documentation.
Add this to your package's pubspec.yaml file:
dependencies:
cloud_firestore: ^0.8.2+2
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.
Now in your Dart code, you can use:
import 'package:cloud_firestore/cloud_firestore.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
0.9.0+2 | Feb 15, 2019 |
|
|
0.9.0+1 | Feb 8, 2019 |
|
|
0.9.0 | Jan 25, 2019 |
|
|
0.8.2+3 | Nov 8, 2018 |
|
|
0.8.2+2 | Nov 8, 2018 |
|
|
0.8.2+1 | Oct 18, 2018 |
|
|
0.8.1+1 | Oct 12, 2018 |
|
|
0.8.1 | Oct 2, 2018 |
|
|
0.8.0 | Sep 5, 2018 |
|
|
0.7.4 | Jul 23, 2018 |
|
|
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
|
We analyzed this package on Feb 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter
References Flutter, and has no conflicting libraries.
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 | 0.3.0+1 |
flutter | 0.0.0 | ||
meta | ^1.0.5 | 1.1.6 | 1.1.7 |
Transitive dependencies | |||
sky_engine | 0.0.99 | ||
typed_data | 1.1.6 | ||
vector_math | 2.0.8 | ||
Dev dependencies | |||
flutter_test |