Skip to main content
RapidDev - Software Development Agency
flutterflow-tutorials

How to Update Data in Your FlutterFlow Firestore Database

Update Firestore data in FlutterFlow using the Update Document backend action, which only modifies the fields you specify without overwriting the rest. Use FieldValue.increment for counters, FieldValue.arrayUnion for adding to arrays, and Custom Actions with WriteBatch for updating multiple documents atomically. For read-then-write patterns, use Firestore transactions to prevent concurrent-write conflicts.

What you'll learn

  • How to configure the Update Document action in FlutterFlow's Action Flow editor
  • How to use FieldValue.increment for safe counter updates without overwrite conflicts
  • How to add and remove items from array fields using FieldValue.arrayUnion and arrayRemove
  • How to perform atomic batch updates across multiple documents using a Custom Action
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Intermediate9 min read20-35 minFlutterFlow Free+March 2026RapidDev Engineering Team
TL;DR

Update Firestore data in FlutterFlow using the Update Document backend action, which only modifies the fields you specify without overwriting the rest. Use FieldValue.increment for counters, FieldValue.arrayUnion for adding to arrays, and Custom Actions with WriteBatch for updating multiple documents atomically. For read-then-write patterns, use Firestore transactions to prevent concurrent-write conflicts.

Partial updates, atomic counters, and safe concurrent writes in Firestore

FlutterFlow's Update Document action lets you modify specific fields in a Firestore document without touching anything else. This is the correct approach for most edits — editing a user's display name should not risk clobbering their email or role. Beyond basic field updates, Firestore offers special FieldValue operations that are safe under concurrent access: increment a view counter without reading the old value first, append a tag to an array without duplicating it, or remove a specific item from a list. For workflows where you need to read a document and then update it based on what you read, Firestore transactions ensure no other write can interfere between the read and the write.

Prerequisites

  • A FlutterFlow project with Firebase/Firestore connected (Settings → Project Setup → Firebase)
  • At least one Firestore collection with documents to update
  • Basic familiarity with FlutterFlow's Action Flow editor and Page State variables
  • Understanding of document references — how to pass a document reference to an action

Step-by-step guide

1

Use the Update Document action for basic field updates

In FlutterFlow, select the widget that triggers the update (e.g., a Save button). Open its Action Flow. Add a Backend Call action → Update Document. Select the collection you want to update. For the document reference, either pass it as a Page Parameter (if navigating from a list) or fetch it via a Backend Query first. Under Fields to Update, click Add Field for each field you want to change. Set the field name and bind the value from a TextField or Page State variable. Fields you do NOT list here remain unchanged — this is a partial update, not a full document replace.

Expected result: The specified fields are updated in Firestore. Other fields on the document remain untouched. A confirmation Snackbar appears if you add a Show Snackbar action after the update.

2

Use FieldValue.increment for counters to prevent overwrite conflicts

When multiple users can update the same numeric field (view counts, like counts, stock quantities), reading the value, adding 1, and writing it back creates race conditions. Two users reading simultaneously both see 5, both write 6 — one increment is lost. Fix this with a Custom Action using FieldValue.increment. In FlutterFlow, go to Custom Code → Custom Actions → Add Action. Import 'package:cloud_firestore/cloud_firestore.dart'. Write the function body: await FirebaseFirestore.instance.collection('posts').doc(postId).update({'viewCount': FieldValue.increment(1)}). Call this action from your Action Flow instead of the standard Update Document action for counter fields.

increment_field.dart
1// Custom Action: incrementField
2// Parameters: collectionPath (String), docId (String), fieldName (String), incrementBy (double)
3import 'package:cloud_firestore/cloud_firestore.dart';
4
5Future incrementField(
6 String collectionPath,
7 String docId,
8 String fieldName,
9 double incrementBy,
10) async {
11 await FirebaseFirestore.instance
12 .collection(collectionPath)
13 .doc(docId)
14 .update({fieldName: FieldValue.increment(incrementBy)});
15}

Expected result: The counter increments atomically. Even if 100 users click simultaneously, each increment is applied independently and no updates are lost.

3

Add and remove array items with FieldValue.arrayUnion and arrayRemove

For fields that are arrays (tags, liked post IDs, category selections), avoid reading the array, modifying it in Dart, and writing the whole array back — this loses concurrent changes. Use two Custom Actions instead. arrayUnion adds an item only if it does not already exist (no duplicates). arrayRemove removes all instances of the specified item. Create a Custom Action named toggleFavorite that takes a productId String. Inside: if adding, call .update({'favoriteIds': FieldValue.arrayUnion([productId])}). If removing, call .update({'favoriteIds': FieldValue.arrayRemove([productId])}). Pass a boolean parameter isFavoriting to choose which path to take.

toggle_favorite.dart
1// Custom Action: toggleFavorite
2// Parameters: userId (String), productId (String), isFavoriting (bool)
3import 'package:cloud_firestore/cloud_firestore.dart';
4
5Future toggleFavorite(
6 String userId,
7 String productId,
8 bool isFavoriting,
9) async {
10 final userRef = FirebaseFirestore.instance
11 .collection('users')
12 .doc(userId);
13 if (isFavoriting) {
14 await userRef.update({
15 'favoriteIds': FieldValue.arrayUnion([productId]),
16 });
17 } else {
18 await userRef.update({
19 'favoriteIds': FieldValue.arrayRemove([productId]),
20 });
21 }
22}

Expected result: Favorites are added or removed without duplicates or race conditions. The favoriteIds array reflects accurate state even with concurrent updates.

4

Batch update multiple documents atomically

If you need to update several documents together — for example, marking all messages in a conversation as read, or updating a product's price across a cart and an order — use a WriteBatch so either all updates succeed or none do. Create a Custom Action named batchUpdateReadStatus. Parameters: conversationId (String), userId (String). Inside: get a WriteBatch via FirebaseFirestore.instance.batch(). Query unread messages. For each, call batch.update(docRef, {'readBy': FieldValue.arrayUnion([userId])}). After the loop, await batch.commit(). Firestore WriteBatch supports up to 500 operations per commit. If you need more, split into multiple batches.

batch_mark_read.dart
1// Custom Action: batchMarkRead
2// Parameters: conversationId (String), userId (String)
3import 'package:cloud_firestore/cloud_firestore.dart';
4
5Future batchMarkRead(
6 String conversationId,
7 String userId,
8) async {
9 final messagesRef = FirebaseFirestore.instance
10 .collection('conversations')
11 .doc(conversationId)
12 .collection('messages');
13 final unread = await messagesRef
14 .where('readBy', whereNotIn: [[userId]])
15 .limit(500)
16 .get();
17 if (unread.docs.isEmpty) return;
18 final batch = FirebaseFirestore.instance.batch();
19 for (final doc in unread.docs) {
20 batch.update(doc.reference, {
21 'readBy': FieldValue.arrayUnion([userId]),
22 });
23 }
24 await batch.commit();
25}

Expected result: All targeted documents are updated in a single atomic operation. If any single update fails, none of them commit — preventing partial state.

5

Use Firestore transactions for read-then-update patterns

When your update logic depends on the current value of a field — for example, booking a seat only if the available count is still above zero — you must use a transaction. A transaction reads a document and then updates it in an atomic sequence. If another write modifies the document between your read and write, Firestore automatically retries the transaction. Create a Custom Action named bookSeat. Inside: FirebaseFirestore.instance.runTransaction((transaction) async { final snap = await transaction.get(eventRef); final available = snap.data()!['availableSeats'] as int; if (available <= 0) throw Exception('No seats available'); transaction.update(eventRef, {'availableSeats': FieldValue.increment(-1)}); transaction.set(bookingRef, {'userId': userId, 'eventId': eventId, 'bookedAt': FieldValue.serverTimestamp()}); }). If you need expert help structuring complex transaction logic across multiple collections, RapidDev has implemented this pattern across hundreds of FlutterFlow apps.

Expected result: Seat booking is race-condition safe. Two users attempting to book the last seat simultaneously will result in one success and one failure, never an oversold event.

Complete working example

firestore_update_helpers.dart
1import 'package:cloud_firestore/cloud_firestore.dart';
2
3// 1. Increment a numeric field atomically
4Future<void> incrementField(
5 String collectionPath,
6 String docId,
7 String fieldName,
8 double amount,
9) async {
10 await FirebaseFirestore.instance
11 .collection(collectionPath)
12 .doc(docId)
13 .update({fieldName: FieldValue.increment(amount)});
14}
15
16// 2. Toggle an item in an array field
17Future<void> toggleArrayItem(
18 String collectionPath,
19 String docId,
20 String fieldName,
21 String item,
22 bool adding,
23) async {
24 await FirebaseFirestore.instance
25 .collection(collectionPath)
26 .doc(docId)
27 .update({
28 fieldName: adding
29 ? FieldValue.arrayUnion([item])
30 : FieldValue.arrayRemove([item]),
31 });
32}
33
34// 3. Batch update up to 500 docs
35Future<void> batchSetField(
36 List<DocumentReference> refs,
37 String fieldName,
38 dynamic value,
39) async {
40 final batch = FirebaseFirestore.instance.batch();
41 for (final ref in refs) {
42 batch.update(ref, {fieldName: value});
43 }
44 await batch.commit();
45}
46
47// 4. Transaction: decrement with floor check
48Future<bool> decrementIfPositive(
49 DocumentReference docRef,
50 String fieldName,
51) async {
52 bool success = false;
53 await FirebaseFirestore.instance.runTransaction((txn) async {
54 final snap = await txn.get(docRef);
55 final current = (snap.data() as Map<String, dynamic>)[fieldName] as int;
56 if (current <= 0) throw Exception('Cannot decrement below zero');
57 txn.update(docRef, {fieldName: FieldValue.increment(-1)});
58 success = true;
59 });
60 return success;
61}

Common mistakes when updating Data in Your FlutterFlow Firestore Database

Why it's a problem: Reading a counter value, incrementing it in app state, then writing the new value back

How to avoid: Use FieldValue.increment(1) in a Custom Action. Firestore applies the increment server-side atomically regardless of how many concurrent writes occur.

Why it's a problem: Using the standard Update Document action to modify an array field by passing the entire new array

How to avoid: Use FieldValue.arrayUnion([newItem]) to append an item that doesn't already exist, and FieldValue.arrayRemove([item]) to delete a specific item. Both are atomic and safe under concurrent access.

Why it's a problem: Not passing a document reference to the Update Document action — using collection + manually typed ID instead

How to avoid: Always carry the DocumentReference from the Backend Query result to your update action. In FlutterFlow, query results expose a reference field alongside the data fields.

Best practices

  • Always use partial updates (Update Document with specific fields) rather than replacing entire documents — prevents clobbering fields you didn't intend to change
  • Use FieldValue.serverTimestamp() for updatedAt fields instead of DateTime.now() — server timestamps are consistent across timezones and not subject to client clock drift
  • Show a loading indicator during update operations and disable the save button to prevent duplicate submissions
  • Add a confirmation Snackbar after successful updates so users know their change was saved
  • For any field that multiple users can modify concurrently (likes, ratings, inventory), always use FieldValue.increment or transactions — never read-modify-write
  • Validate input on the FlutterFlow side before calling Update Document to avoid writing invalid data to Firestore
  • Test concurrent updates by opening two browser tabs in Run mode and making simultaneous changes to verify your atomic update logic works correctly

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

I am building a FlutterFlow app with Firestore. I need to update data safely in three scenarios: (1) incrementing a like count when multiple users can tap simultaneously, (2) adding a tag to an array field without duplicating it, and (3) updating a product price across multiple documents at once. Write the Dart Custom Action code for each scenario using FieldValue.increment, FieldValue.arrayUnion, and WriteBatch respectively.

FlutterFlow Prompt

Add a Save button to my profile editing page that updates only the displayName and bio fields of the current user's Firestore document without affecting any other fields. Show a success Snackbar after saving and re-enable the button if the update fails.

Frequently asked questions

How do I update a Firestore document in FlutterFlow?

Use the Backend Call action in your Action Flow and select Update Document. Choose the collection, supply the document reference (from a Backend Query result or Page Parameter), then list the specific fields you want to change and bind their values to your form inputs or Page State variables. Only the fields you list will be modified — all other fields remain unchanged.

How do I increment a counter in FlutterFlow without overwriting concurrent changes?

Create a Custom Action that uses FieldValue.increment(1) from the cloud_firestore package. This applies the increment server-side atomically. Never read the counter value, add to it locally, and write it back — that pattern loses concurrent increments.

Can I update multiple Firestore documents at the same time in FlutterFlow?

Yes, using a Custom Action with WriteBatch. Get a batch via FirebaseFirestore.instance.batch(), call batch.update(ref, fields) for each document, then await batch.commit(). A single batch supports up to 500 operations. All updates either succeed together or fail together.

What is the difference between Update Document and replacing an entire document in FlutterFlow?

Update Document performs a partial update — only the fields you specify change, and all other fields remain as they were. If you use set() without merge:true, it replaces the entire document, deleting fields you did not include. Always use Update Document (which maps to Firestore's update() method) when you only want to change specific fields.

How do I add an item to an array field in Firestore from FlutterFlow?

Create a Custom Action using FieldValue.arrayUnion([yourItem]). This adds the item only if it is not already present in the array. For removing an item, use FieldValue.arrayRemove([yourItem]). Both operations are atomic and safe for concurrent use. Avoid reading the array, modifying it in memory, and writing the whole array back.

My update succeeds but the UI does not refresh — how do I fix this?

If your Backend Query is set to Single Time Query (one-time), it does not listen for changes. Either switch to real-time (toggle Single Time Query off) or add a Refresh Page / re-trigger the Backend Query action after the update completes. For real-time listeners, the UI should update automatically within 1-2 seconds.

What if I need help implementing complex transactional update logic across multiple collections?

Multi-collection transactions with rollback logic and concurrent-user safety can be complex to get right in FlutterFlow Custom Actions. RapidDev has implemented this pattern across hundreds of production FlutterFlow apps and can help design and implement the right architecture for your use case.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.