Код: Выделить всё
if (imageState is AsyncImagePainter.State.Error)
это мой код
Код: Выделить всё
@Composable
fun Product(product: Product) {
val imageState = rememberAsyncImagePainter(
model = ImageRequest.Builder(LocalContext.current).data(product.thumbnail)
.size(Size.ORIGINAL).build()
)
Column(
modifier = Modifier
.clip(RoundedCornerShape(20.dp))
.height(300.dp)
.fillMaxWidth()
.background(MaterialTheme.colorScheme.primaryContainer)
) {
if (imageState is AsyncImagePainter.State.Error) {
Box(
modifier = Modifier
.fillMaxWidth()
.height(200.dp),
contentAlignment = Alignment.Center
) {
CircularProgressIndicator()
}
}
if (imageState is AsyncImagePainter.State.Success) {
Image(
modifier = Modifier
.fillMaxWidth()
.height(200.dp),
painter = imageState.painter,
contentDescription = product.title,
contentScale = ContentScale.Crop
)
}
Spacer(modifier = Modifier.height(6.dp))
Text(
modifier = Modifier.padding(horizontal = 16.dp),
text = "${product.title} -- Price: ${product.price}$",
fontSize = 17.sp,
fontWeight = FontWeight.SemiBold
)
Spacer(modifier = Modifier.height(6.dp))
Text(
modifier = Modifier.padding(horizontal = 16.dp),
text = product.description,
fontSize = 13.sp,
)
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... wing-image
Мобильная версия