Updating an existing Juice in the final application does not work because the juice instance passed to SheetForm is stale, but is copied into the view model's _currentJuiceStream by the combined behaviors of SheetForm's various ...InputRow.on...Change lambdas and the view model updateCurrentJuice function passed to SheetForm as lambda parameter onUpdateJuice by EntryBottomSheet.
This can be corrected by changing the 'juice: Juice' parameter of SheetForm to 'juiceFlow: StateFlow' and adding 'val juice by juiceFlow.collectAsState()' to the function body. Also change calling parameter 'juice = juice' in the invocation of SheetForm in EntryBottomSheet to 'juiceFlow = juiceTrackerViewModel.currentJuiceStream'. 'val juice by juiceTrackerViewModel.currentJuiceStream.collectAsState()' can then be removed from EntryBottomSheet.
Updating an existing Juice in the final application does not work because the juice instance passed to SheetForm is stale, but is copied into the view model's _currentJuiceStream by the combined behaviors of SheetForm's various ...InputRow.on...Change lambdas and the view model updateCurrentJuice function passed to SheetForm as lambda parameter onUpdateJuice by EntryBottomSheet.
This can be corrected by changing the 'juice: Juice' parameter of SheetForm to 'juiceFlow: StateFlow' and adding 'val juice by juiceFlow.collectAsState()' to the function body. Also change calling parameter 'juice = juice' in the invocation of SheetForm in EntryBottomSheet to 'juiceFlow = juiceTrackerViewModel.currentJuiceStream'. 'val juice by juiceTrackerViewModel.currentJuiceStream.collectAsState()' can then be removed from EntryBottomSheet.