I have screen that should display one three things: (I'm also very new to Jetpack Compose)
A Loader() if loading An AlertDialog() if there's an error And finally, based on an int from my viewModel, a new ScreenX()
I make an API call in my viewModel and update the 3 state variables accordingly. The problem is that all of the views seem to be appearing over top of each other.
If I try and return Loader(), I get an error.
Maybe this isn't the correct way to do this, but is there any way you can have dynamic screens in a Composable?
@Composable
fun ConnectionScreen(
ip: String,
viewModel: BridgeViewModel,
navController: NavHostController
) {
val page = viewModel.page.collectAsState()
val loading = viewModel.loading.collectAsState()
val error = viewModel.error.collectAsState()
Scaffold {
if (loading.value) {
Loader()
}
error.value?.let {
AlertDialogWithButtons(
title = "Error",
message = it,
onNegativeClick = { },
onPositiveClick = {},
)
}
when (page.value) {
0 -> Screen0()
1 -> Screen1()
2 -> Screen2()
}
}
}