Skip to content

Commit

Permalink
Merge pull request #23 from bhoominn/patch-1
Browse files Browse the repository at this point in the history
Use FieldValue.increment()
  • Loading branch information
Kennygunderman committed Apr 11, 2021
2 parents d8d480a + 2ce74ff commit 05466f3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/data/repo/chatroom_repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ class ChatRoomRepo {
FirebaseFirestore.instance.collection('chat_rooms');

void incrementSnacksSent(String chatRoomId) async {
final doc = await _ref.doc(chatRoomId).get();
final int currentSent = doc['snacks_sent'];
_ref.doc(chatRoomId).update({'snacks_sent': currentSent + 1});
//final doc = await _ref.doc(chatRoomId).get();
//final int currentSent = doc['snacks_sent'];
//_ref.doc(chatRoomId).update({'snacks_sent': currentSent + 1});

_ref.doc(chatRoomId).update({'snacks_sent': FieldValue.increment(1});
}

Stream<List<ChatRoom>> getChatRooms() async* {
Expand Down

0 comments on commit 05466f3

Please sign in to comment.