Fix Android Crash
This commit is contained in:
parent
ff45436e74
commit
5bf418db58
1 changed files with 11 additions and 8 deletions
|
|
@ -39,6 +39,8 @@ import cafe.adriel.voyager.navigator.LocalNavigator
|
||||||
import cafe.adriel.voyager.navigator.currentOrThrow
|
import cafe.adriel.voyager.navigator.currentOrThrow
|
||||||
import io.kamel.image.KamelImage
|
import io.kamel.image.KamelImage
|
||||||
import io.kamel.image.asyncPainterResource
|
import io.kamel.image.asyncPainterResource
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
|
|
@ -55,18 +57,19 @@ data class DetailScreen(
|
||||||
var pokemonData by remember { mutableStateOf<PokemonData?>(null) }
|
var pokemonData by remember { mutableStateOf<PokemonData?>(null) }
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
pokemonData = fetchPokemonDetails();
|
pokemonData = withContext(Dispatchers.IO) {
|
||||||
|
fetchPokemonDetails();
|
||||||
|
}
|
||||||
dataLoaded = true;
|
dataLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(dataLoaded, pokemon) {
|
|
||||||
if (dataLoaded) {
|
|
||||||
navigator.push(DetailScreen(pokemon))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dataLoaded) {
|
if (!dataLoaded) {
|
||||||
navigator.push(LoadingScreen())
|
Box(
|
||||||
|
modifier = Modifier.background(color = Color.White).fillMaxSize(),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Text("Fetching Data from API...")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier.background(color = Color.White).fillMaxSize(),
|
modifier = Modifier.background(color = Color.White).fillMaxSize(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue