In all the examples I have seen with view models in combination with Jetpack Compose, one usually stores a state in the view model as MutableStateFlow and then applies collectAsState in the compose function in order to get a Compose state.
My question: Why not store the state directly in the view model, and not some flow? E.g.
class MyViewModel: ViewModel() {
val showDialog = mutableStateOf(false)
}
@Compose
fun MyScreen(viewModel: MyViewModel) {
Button(onClick = { viewModel.showDialog = true })
if (viewModel.showDialog) {
AlertDialog(...)
}
}
The above code seems to run as intended. Is this a valid solution then?