Samuel
10/05/2024, 3:45 PM@Composable fun
, load initial at ID, HTTP GET, load internal `Composable`s based on that data?
My current approach:
var lastErrorStr by remember { mutableStateOf("") }
val thingName by remember { mutableStateOf("") }
val thingImgUrl by remember { mutableStateOf("") }
val myId by remember { mutableStateOf(myIdFromInputOfThisFunc) }
val scope = rememberCoroutineScope()
TextField(value = myId, label = { Text("enter ID") })
LaunchedEffect(myId) {
try {
val thing = scope.async {
myApi.getById(barcode)
}.await().thing
thingName = thing.name
thingImgUrl = thing.imgUrl
} catch (e: SocketTimeoutException) {
lastErrorStr = "[SocketTimeoutException] ${e.message}"
} /* other error handling omitted for brevity */
}
AnimatedVisibility(thingName.isNotEmpty()
&& lastErrorStr.isEmpty()) {
Text(thingName)
AnimatedVisibility(thingImgUrl.isNotEmpty()) {
SubcomposeAsyncImage(model = thingImgUrl)
}
}
AnimatedVisibility(lastErrorStr.isNotEmpty()) {
Text(lastErrorStr, color = Color.Red)
}
Mark Murphy
10/05/2024, 5:35 PMSamuel
10/05/2024, 6:41 PMDavid Breneisen
10/05/2024, 10:05 PMSamuel
10/06/2024, 2:37 AM