Update: Add to List Problem. Only first item being selected.

Actions & Logic

Update:
"On further investigation, the selection is happening only on the first item in the list. No matter how many items are selected, only the first one gets added to the list."

Product Selection and Order Workflow

I'm building a feature to allow users to select products and add them to an order in FlutterFlow. Here's the breakdown:

  • Firestore: "Products" collection with product data, including "title" and "isSelected" fields.

  • Custom Component: Displays individual products in a ListView with a toggle for selection.

    • Parameters: itemDocRef (Document Reference).

    • Component State: isSelected (List of Document References).

    • On toggle:

      • Sets isSelected field in the products collection from isToggled local state

      • Adds/removes itemDocRef from isSelected, and updates the selectedRefsAppLevel App State. This is done on every toggle.

  • App State: selectedRefsAppLevel (List of Document References): Stores selected product references.

  • Main Page:

    • ListView displays products using the custom component. The component's itemDocRef parameter is bound to the ListView's query.

    • "Create Order" Button:

      • Updates the selectedRefsAppLevel App State with the component's isSelected value.

      • Loop Action: Iterates through selectedRefsAppLevel, queries Firestore for each product, and displays info in a Snackbar.

Problem:

The 'add to list' action isn't working as expected; the list count remains 1. It seems like the document is being replaced inside of the list rather than being added.

How I know:

  • I have a snackbar after the isSelected field is set. It displays the current state of the isToggle local state variable to confirm the input to the conditional statement.

  • Conditional statement: If isToggled == true, add (itemDocRef) to list selectedItems

  • A snackbar displaying the number of items in the selectedItems list is located under each branch of the conditional statement.

  • Both Snackbars currently show 1, no matter how many times I add an item.

Essentially, users select products via toggles in a ListView, and the selected product references are stored and processed when creating an order

EDIT: When

What have you tried so far?

What I've tried:

  • Displayed the state of the isToggle local state variable.

  • Displayed the number of items in the selectedItems list under each branch of the conditional statement.

  • Verified that the binding is actually set to 'add to list' and not set or something else

Did you check FlutterFlow's Documentation for this topic?
No
3
11 replies