feat(ui): show product images in list/detail
Build Android app / Build (push) Has been cancelled
Build iOS app / Build (push) Has been cancelled
Template Cleanup / Template Cleanup (push) Has been cancelled

This commit is contained in:
xiaobai committed 2026-03-04 16:25:06 +08:00
1 parent 035d396eaf
commit 575c26eaf5
3 files changed
+24 -7

No files matched your search

@@ -43,6 +43,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import coil3.compose.AsyncImage
import com.example.minishop.cart.CartItem import com.example.minishop.cart.CartItem
import com.example.minishop.cart.CartRepository import com.example.minishop.cart.CartRepository
import com.example.minishop.checkout.CheckoutService import com.example.minishop.checkout.CheckoutService
@@ -247,6 +248,7 @@ private fun ProductListScreen(
items(products) { p -> items(products) { p ->
ElevatedCard(onClick = { onClick(p) }, modifier = Modifier.fillMaxWidth()) { ElevatedCard(onClick = { onClick(p) }, modifier = Modifier.fillMaxWidth()) {
Column(Modifier.padding(12.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) { Column(Modifier.padding(12.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
ProductCover(p.imageUrl)
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) { Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
Text(p.title, style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.SemiBold) Text(p.title, style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.SemiBold)
PriceTag(p.price) PriceTag(p.price)
@@ -297,6 +299,7 @@ private fun ProductDetailScreen(
shape = RoundedCornerShape(14.dp) shape = RoundedCornerShape(14.dp)
) { ) {
Column(Modifier.padding(14.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) { Column(Modifier.padding(14.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
ProductCover(product.imageUrl)
Text(product.title, style = MaterialTheme.typography.headlineSmall, fontWeight = FontWeight.Bold) Text(product.title, style = MaterialTheme.typography.headlineSmall, fontWeight = FontWeight.Bold)
PriceTag(product.price) PriceTag(product.price)
Text(product.description) Text(product.description)
@@ -382,6 +385,18 @@ private fun CartScreen(
} }
} }
@Composable
private fun ProductCover(url: String) {
AsyncImage(
model = if (url.isNotBlank()) url else "https://picsum.photos/seed/fallback/600/360",
contentDescription = null,
modifier = Modifier
.fillMaxWidth()
.height(150.dp)
.clip(RoundedCornerShape(12.dp))
)
}
@Composable @Composable
private fun SmallOpButton(text: String, onClick: () -> Unit) { private fun SmallOpButton(text: String, onClick: () -> Unit) {
OutlinedButton(onClick = onClick) { OutlinedButton(onClick = onClick) {
@@ -12,5 +12,7 @@ data class Product(
@SerialName("price") @SerialName("price")
val price: Double, val price: Double,
@SerialName("description") @SerialName("description")
val description: String val description: String,
@SerialName("imageUrl")
val imageUrl: String = ""
) )
@@ -16,11 +16,11 @@ class ProductApi(
} }
private fun mockProducts(): List<Product> = listOf( private fun mockProducts(): List<Product> = listOf(
Product("1", "KMP 入门课", 99.0, "跨平台开发基础课程"), Product("1", "KMP 入门课", 99.0, "跨平台开发基础课程", "https://picsum.photos/seed/kmp1/600/360"),
Product("2", "Compose 实战课", 149.0, "Compose 多端 UI 实战"), Product("2", "Compose 实战课", 149.0, "Compose 多端 UI 实战", "https://picsum.photos/seed/kmp2/600/360"),
Product("3", "Kotlin 协程训练营", 129.0, "协程与 Flow 进阶"), Product("3", "Kotlin 协程训练营", 129.0, "协程与 Flow 进阶", "https://picsum.photos/seed/kmp3/600/360"),
Product("4", "Clean 架构速成", 199.0, "从0构建可维护架构"), Product("4", "Clean 架构速成", 199.0, "从0构建可维护架构", "https://picsum.photos/seed/kmp4/600/360"),
Product("5", "SQLDelight 实战", 119.0, "KMP 本地数据库方案"), Product("5", "SQLDelight 实战", 119.0, "KMP 本地数据库方案", "https://picsum.photos/seed/kmp5/600/360"),
Product("6", "Ktor API 实战", 159.0, "跨平台网络层搭建") Product("6", "Ktor API 实战", 159.0, "跨平台网络层搭建", "https://picsum.photos/seed/kmp6/600/360")
) )
} }