Skip to content

Commit

Permalink
Add Firestore transaction example (flutter#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
kroikie authored and collinjackson committed May 7, 2018
1 parent 4f7ec09 commit c20c3a5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/cloud_firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.7.0+1

* Add transactions example to README.

## 0.7.0

* **Breaking change**. `snapshots` is now a method instead of a getter.
Expand Down
12 changes: 12 additions & 0 deletions packages/cloud_firestore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ class BookList extends StatelessWidget {
}
```

Running a transaction:

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

## Getting Started

See the `example` directory for a complete sample app using Cloud Firestore.
2 changes: 1 addition & 1 deletion packages/cloud_firestore/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Cloud Firestore, a cloud-hosted, noSQL database
live synchronization and offline support on Android and iOS.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/cloud_firestore
version: 0.7.0
version: 0.7.0+1

flutter:
plugin:
Expand Down

0 comments on commit c20c3a5

Please sign in to comment.