I know there have been certain questions on state management in flutter, but none of them seemed to solve my use case.
Recently I was building an app based on E-commerce and encountered this real need for state management. I had 2 pages,
- One is the products page, where I add a product to the cart.
- Second is the cart page, where I see products added recently to cart.
Users can add the product to the cart and then navigate to the cart. In the cart page, they can also increase or decrease the quantity of the item.
As you can see, initially yellow item was added to the cart with quantity 3, but in the cart page, user pressed the (-) button and reduced the quantity to 1. Now if the user presses the back button, then the state of the yellow product will be still 3 on the products page. Similar situation with the pink product.
Hence I tried to resolve this using normal setState and some global data structures to keep track of the quantity. But as my app grew big, its really hard to maintain the state across the pages. I have read about different state management solutions like redux, BloC pattern, Provider, ... but I am not clear how to use any of them in my use case. Could anyone with experience, break down the rock and help me digest?
Any sample code and explanation about how to solve this would be appreciated!
Hope my problem is clear!