flutter_firestore_tut
//... | |
class _Home extends State<StatefulWidget> { | |
//... | |
void interact() async { | |
final DocumentReference postRef = | |
Firestore.instance.collection('stats').document('interactions'); | |
await Firestore.instance.runTransaction((Transaction tx) async { | |
DocumentSnapshot postSnapshot = await tx.get(postRef); | |
if (postSnapshot.exists) { | |
await tx.update(postRef, | |
<String, dynamic>{'count': postSnapshot.data['count'] + 1}); | |
} | |
}); | |
} | |
//... | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
//... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment