【发布时间】:2021-11-01 22:53:32
【问题描述】:
@Composable
fun CategorySection(context: Context) {
Column(modifier = Modifier.padding(8.dp)) {
Text(
text = "Api Data",
style = MaterialTheme.typography.h5,
modifier = Modifier.padding(vertical = 7.dp, horizontal = 8.dp)
)
val coroutineScope = rememberCoroutineScope()
coroutineScope.launch(Dispatchers.Main) {
val response = ApiPhoto.apiService.getPhotos()
if (response.isSuccessful && response.body() != null) {
val photos = response.body()
photos?.let {
CategoryItemSection(it)
}
} else {
Toast.makeText(
context,
"Error Occurred: ${response.message()}",
Toast.LENGTH_LONG
).show()
}
}
}
}
@Composable
fun CategoryItemSection(photos: List<Photo>) {
LazyColumn(
modifier = Modifier.fillMaxWidth()
){
items(photos.size){
CardView(photos[it])
}
}
}
【问题讨论】:
-
请提供更多信息 - 错误发生在哪一行,完整的堆栈跟踪是什么,您尝试修复什么?
标签: android kotlin kotlin-coroutines android-jetpack-compose android-jetpack