Skip to content
Tech Stack25 November 2026 · 11 min read

FlutterFlow Components Without Shared State Bugs

When one row's expanded or favorite state lands on another after a refresh, give each value one owner, key rows by record ID and run a reorder test.

FlutterFlow Components Without Shared State Bugs

What you'll learn

  • Why does one row's state appear on another row?
  • Give each value one owner
  • Why a single App State flag opens every row
Article contents

You tap the chevron on the second card in a list and the details open. Then the list refreshes, a new item arrives at the top, and the details are now open on a different card. Or you mark one item as a favorite, scroll, and the filled heart appears on its neighbor instead. The component looks correct in isolation, so the bug seems to come from nowhere.

The short answer: each value in a repeated row needs exactly one owner, and every row needs an identity that comes from its record rather than from its position in the list. Keep display-only state such as "expanded" inside the component, store anything that must survive a refresh on the record itself, keep single page-wide choices in page state, and pass the record's reference through every action instead of a list index.

The examples below use a synthetic demonstration: a Firestore collection called demo_tasks with the fields title, notes, isFavorite and sortOrder, and a FlutterFlow component called TaskCard. The FlutterFlow steps and the Dart sample follow the current FlutterFlow and Flutter documentation. They were not run in a FlutterFlow project for this article, so the test at the end is the procedure you still need to execute.

Why does one row's state appear on another row?

Without a key, Flutter matches the widgets of a rebuilt list to the existing ones by their type and their position, and any state held by those widgets stays at that position. The Flutter documentation for ValueKey describes the exact case: when a list is reversed, "Flutter matches widgets by position", so state held by stateful widgets "can be reused for a different piece of data".

Diagram of a three-row list where Task B is expanded, followed by the same list after a new Task A2 is inserted at the top. When rows are matched by position, the expanded state stays at index 1 and appears on Task A. When rows are matched by record ID, the expanded state stays on Task B at its new index 2.

In the diagram, Task B is expanded before the refresh. A new Task A2 is inserted at the top, so Task B moves from index 1 to index 2. When matching uses position, the state for index 1 is kept and now appears on Task A, which is the bug users report. When matching uses the record ID, the state follows Task B.

The general rule is documented on the Key class: a new widget only updates an existing element when its key is the same, keys must be unique among siblings, and attaching the wrong State object to an unkeyed stateful widget "can often be solved by using an appropriate Key". The ValueKey page recommends a value that is "stable and unique for each item, such as an identifier from the data model". A Firestore document ID fits that description. A list index does not, because it changes whenever a row is inserted, removed or reordered.

Give each value one owner

Before you build anything, list every value the card shows or changes and decide where it lives. In the demo there are three, and each belongs to a different scope.

ValueOwnerWhere it livesExpected after a refresh
Is this card expanded?The TaskCard instanceComponent state isExpanded, default falseMay reset to collapsed; must never move to another card
Is this task a favorite?The task recordFirestore field isFavorite on that documentSame value, on the same task
Which task is open in the side panel?The pagePage state selectedTaskRef (one document reference)Same task, or an empty panel if it was deleted

FlutterFlow documents that component state variables are only accessible within the current component's scope and can only be changed through actions. That makes component state a good home for a display flag that only one card cares about. It is a poor home for anything the user expects to keep, because the same page documents that a component's On Initialization actions run again when a hidden component is shown, and that each dynamically generated instance runs them when it is created. A recreated instance starts from its default.

The favorite belongs on the record. The user is stating something about the task, other screens may show it, and it has to be there tomorrow. The selected task belongs to the page because only one can be selected at a time. Store its document reference rather than its index, so a reorder does not change which task the panel shows.

Why a single App State flag opens every row

A global variable has one value for the whole app, so every card that reads it shows the same answer. FlutterFlow describes App State as variables that can be accessed and modified across all pages and components, and recommends page or component state instead for temporary data that does not affect the overall state of the application.

With one boolean App State variable such as isCardExpanded, every card reads the same value, so expanding one card expands all of them. A common workaround is an App State list of expanded indexes. That avoids the shared value, but it stores identity by position again, so it fails after the same insert or reorder. If you truly need expansion to survive navigation, store a list of task IDs instead, and remove an ID when its task is deleted.

Build the card so actions name the record

The component should receive the whole record, keep its own display state, and send the record's reference with every change. In FlutterFlow, the setup looks like this:

  1. Create the demo_tasks collection with the four fields above and add five or six documents with clearly synthetic titles such as "Demo task 1". Give sortOrder distinct numbers so you can reorder rows later by editing them.
  2. On the page, add a ListView and a Firestore query on demo_tasks, ordered by sortOrder. Turn on Listen For Changes, which FlutterFlow's query documentation describes as updating displayed documents when their data changes. Generate dynamic children from the query result.
  3. Create the TaskCard component with one parameter, task, of type Document for demo_tasks. Bind the title, notes and heart icon to that parameter, not to page variables.
  4. Add the component state isExpanded as a boolean with the default false. On the chevron's tap, use Update Component State to set it to its opposite, with the update type Rebuild Current Component so the tap does not rebuild the whole page.
  5. On the heart's tap, run the Firestore Update Document action with the reference of task and set isFavorite to the opposite of the current value. FlutterFlow's Firestore actions identify the document to update by its reference, which acts as a pointer to that exact document.
  6. If the parent needs to react, for example to set selectedTaskRef, add an action parameter to the component that takes a document reference. In the card, call it with Execute Callback and pass task's reference. FlutterFlow's callback documentation shows the same pattern: the child passes a value into the callback and the parent reads it from the callback parameters.

The important part is what you leave out. Neither the card nor the callback receives the list index, and no page or App State variable holds a per-row value. Every change names the document it belongs to, so a reorder between the tap and the write cannot redirect it to another row.

Check how your exported code keys the rows

FlutterFlow's page model documentation says that for dynamic lists of components, the page model keeps a Map<String, FlutterFlowModel> to manage the state of each component instance. It does not say which string identifies an instance, and the generated code can change between releases, so read your own export rather than relying on an article.

Open the code view or download the project and find the ListView that builds TaskCard. Check two things. First, whether the item widget has a key, and what value it uses. Second, which string is used to look up each card's model in that map. If either is derived from the item's index, component state is tied to positions and will move after an insert, removal or reorder. If both use the document ID, state follows the record. In both cases the favorite stays correct, because it is stored on the document and read from it.

When the generated list does not give you the identity you need and you move the list into a custom widget, the plain Flutter fix is small. This sample shows the pattern for a list of DemoTask objects with an id taken from the document ID, where TaskCard is your own stateful widget:

ListView.builder(
  itemCount: tasks.length,
  itemBuilder: (context, index) {
    final task = tasks[index];
    return TaskCard(
      key: ValueKey(task.id),
      task: task,
      onSelected: () => onTaskSelected(task.id),
    );
  },
  findChildIndexCallback: (Key key) {
    final id = (key as ValueKey<String>).value;
    final index = tasks.indexWhere((t) => t.id == id);
    return index >= 0 ? index : null;
  },
)

The ValueKey ties each card's state to its task. The ListView.builder documentation adds that findChildIndexCallback needs to be implemented if the order of children may change later, because without it a child may not map to its existing render object, which "may result in state-loss". If you let users drag rows, Flutter's ReorderableListView requires that "all list items must have a key". For deciding when a list like this should leave the visual builder at all, see when to drop from FlutterFlow custom code to pure Flutter.

Run the identity test before you trust the list

A list that looks correct with static data proves little. The test needs to change positions while state is set, which is the condition that exposes position-based identity. Run it on a build of the app with at least five demo documents.

StepActionExpected result
1Expand task 2 and task 4. Mark task 3 as a favorite.Only tasks 2 and 4 are expanded. Only task 3 shows a filled heart.
2Collapse task 2.Task 4 stays expanded. No other card changes.
3In the Firebase console, give task 4 the lowest sortOrder so it moves to the top.Task 4 appears first. Its expansion is either still open or reset to collapsed, but no other card opens. Task 3 keeps its heart.
4Add a new document with the lowest sortOrder so it appears first.The new task is collapsed and has no heart. Existing cards keep their own state.
5Leave the page and return.Favorites are unchanged. Expansion may reset, but never onto a different card.
6Expand task 5, then delete task 1 in the console.Task 5 stays expanded, and the card that moves into task 1's old position does not inherit any state. If task 1 was selected, the side panel shows an empty state instead of another task.

Step 3 and step 6 are the ones that catch index-based identity. If the expanded state lands on a neighbor in either step, check the key and model lookup described in the previous section. If the heart lands on a neighbor, the favorite is being read from something other than the document, often an App State list indexed by position.

Record the device, the build, and the result of each step. "Expansion reset after refresh" is an acceptable outcome for display state. "Expansion moved to another task" is a defect.

Where this pattern stops

This article covers ownership and identity for one repeated component. It does not compare state management packages, and it does not claim how FlutterFlow's generated list code keys rows in your version, because the documentation does not state it. The FlutterFlow menu names above match the current documentation, but some of those pages were last updated well before the current editor release, so labels may differ slightly in your project. Writes to isFavorite still need Firestore Security Rules that allow only the right user to change that document. Nothing here was executed in a live project.

Start with step 3 of the test on your own list: set one card's state, move that card to the top, and watch where the state goes. If it stays at the old position, you have found the identity problem before your users do. If the same list also has filters, the related article on clearing FlutterFlow filters without stale results covers the query side of the same page.

Free resource

Free SaaS MVP Scope Template

A Notion document with the full feature checklist, MVP vs. nice-to-have table, pre-build questions, and cost signals — so you walk into any developer call knowing exactly what to ask for.

Get the template →
DL

Dusko Licanin

Full-Stack Developer · Banja Luka, Bosnia

Full-stack developer shipping SaaS MVPs, web apps, and mobile apps using AI-augmented workflows — without agency coordination overhead. Live portfolio: BookBed, Callidus, Pizzeria Bestek.

Frequently Asked Questions

Why does a FlutterFlow component in a ListView show another row's state after a refresh?

The component's state is tied to a position in the list rather than to the record it displays. Flutter matches unkeyed widgets by type and position, so when a record is inserted, removed or reordered, the state at that position appears on a different record. The ValueKey documentation recommends keying items with a stable identifier from the data model, such as a Firestore document ID. Values the user must keep, like a favorite, belong on the record itself.

Should I use App State to store each list item's expanded state in FlutterFlow?

No. App State has one value for the whole app, so a single flag expands every card that reads it. FlutterFlow's App State documentation recommends page or component state for temporary data. Use component state for a per-card display flag. If expansion must survive navigation, store a list of record IDs, not indexes, because indexes change when the list changes.

How do I pass the right record from a repeated FlutterFlow component back to the page?

Pass the record's document reference through an action parameter, never the list index. Add an action parameter to the component, call it with Execute Callback, and send the reference of the record the card displays, as the callback documentation shows for passing values to a parent. The page can then store that reference in page state. A reorder between the tap and the handler cannot change which record the reference points to.

Do I need a custom widget to give FlutterFlow list items stable keys?

Not always, so check your exported code before you move anything. FlutterFlow's page model documentation says component instances in dynamic lists are tracked in a map of models, but it does not say which string identifies each instance. If the item key or model lookup comes from the index and state moves in a reorder test, a custom widget that uses ValueKey with the document ID is a direct fix.