bryankeltonadams
04/11/2024, 6:52 AMbryankeltonadams
04/11/2024, 6:54 AMviewModelScope.launch {
savedStateHandle.getStateFlow(key = "customerId", initialValue = null as String?)
.collect {
it?.let {
onCustomerSelected(CustomerUiState(id = it.toInt(), name = "Jim"))
}
}
}
Scaffold {
Column(modifier = Modifier.padding(it)) {
Text("Customer ID: ${customerId ?: "No customer ID provided"}")
Button(onClick = {
navController.previousBackStackEntry?.savedStateHandle?.set(
"customerId",
customerId
)
navController.popBackStack()
}) {
Text("Go back")
}
}
}
bryankeltonadams
04/11/2024, 6:58 AMbryankeltonadams
04/11/2024, 7:08 AMIan Lake
04/11/2024, 1:48 PMbryankeltonadams
04/11/2024, 5:13 PMbryankeltonadams
04/11/2024, 5:15 PMNavBackStackEntry.savedStateHandle
API exists - to offer that generalized approach that doesn't tightly couple screen together.
so I suppose you recommend just using the navBackStackEntry.savedStateHandle and passing the param in, and then using a LaunchedEffect to trigger a viewModel operation.