What's the best way to implement the following scenario using the stacked package?
I have a list of items with price. This list is returned from a future. I also have a datepicker. By changing the date, the list is refreshed with new data. Every time the list gets refreshed, I want to show the subtotal value in the app bar of the page. I tried to wrap the page in the FutureViewModel
class and it works to refresh the list. But I am not sure how to update the subtotal. Should subtotal have a separate modelview? I think the subtotal should be calculated where the list of items exists. I am not sure how to implement this.
Asked
Active
Viewed 51 times
0

B Faley
- 17,120
- 43
- 133
- 223
-
I think you can simply use a List of items returned from the future - and get the subtotal by calling List.fold(...). This way, each time a list is refreshed, and you build your UI - it will simply recalculate your subtotal and show it. Post your build, code, you should be able to get a better answer if you do. – Andrija Dec 07 '22 at 10:05
-
Yea ok I will try to post a simplified version of the code – B Faley Dec 07 '22 at 10:24
-
You can use one ViewModel for it. Just calculate all things in this ViewModel and show in UI. But it can handle only when you have all changing elements on one widget. – fartem Dec 08 '22 at 06:03