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!
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 new StreamBuilder( stream: Firestore.instance.collection('books').snapshots, builder: (context, snapshot) { if (!snapshot.hasData) return new Text('Loading...'); return new ListView( children: snapshot.data.documents.map((document) { return new ListTile( title: new Text(document['title']), subtitle: new Text(document['author']), ); }).toList(), ); }, ); } }
See the example
directory for a complete sample app using Cloud Firestore.