List of lists appropriate state managemnet

Actions & Logic

Hi,

I am trying to create a simple situation for a shopping lists. I have a list of many products and would like to show the amount of products in the shopping list.

I have a page with the list of all products, that is taken from the API call. Also, I have the currently added product stored locally on the phone in the SQL lite.

The issue that I have is the appropriate state management with this - as I can have 100 products available, while only 10 are already added to the shopping list (with the different quantity, as I have the + and - buttons).

What would you suggest for the state management? Should the page hold the list of all the shopping list elements and the callbacks to every element should be provided with the quantity from the shopping list? Or should the quantity be taken by every element itself? Or is there something else that I haven't think about but it seems like a common problem that should have some best practices in mind.

If someone has any ideas of how something like this should be tackled, I would be extremely glad for it! Thanks!

Hubert

What have you tried so far?

Different ways of tackling it, yet all the time I struggle with some small issues so that the quantity is properly updated and the products are immediately shown.

I have couple of different solutions in mind, but this is one of this:

  1. Page state - shopping list elements

  2. Component state - quantity (just for calculation)

  3. Component parameters - quantity (calculated from shopping list or 0), callbacks to add and remove

  4. + and - buttons - runs callbacks provided in the parameters and updates the quantity state

    The text for the quantity then will be the component state, which after rebuilding the component should work, but seems like it doesnt

Did you check FlutterFlow's Documentation for this topic?
Yes
1
2 replies