Within MenuPage.kt we will design a composable for a productitem and then the page with a LazyColumn.
Add black_coffee.png
dummy image for testing purposes
ProductItem (Dummy)
fun Double.format(digits: Int) = "%.${digits}f".format(this)
@Composable
fun ProductItem(product: Product, onAdd: (Product)->Unit) {
Column(
modifier = Modifier
.fillMaxWidth()
.background(Color.White)
) {
Image(
painter = painterResource(id = R.drawable.black_coffee),
contentDescription = "Image for ${product.name}",
contentScale = ContentScale.FillWidth,
modifier = Modifier
.fillMaxWidth()
.height(180.dp)
)
Row(
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier
.padding(16.dp)
.fillMaxWidth()
) {
Column {
Text(product.name, fontWeight = FontWeight.Bold)
Text("$${product.price.format(2)} ea")
}
Button(
colors = ButtonDefaults.buttonColors(
backgroundColor = Alternative1,
contentColor = Color.White
),
onClick = {
onAdd(product)
},
) {
Text("Add")
}
}
}
}
ProductPage (with dummy content)
@Composable
fun MenuPage(dataManager: DataManager) {
LazyColumn {
items(5) {
Card(
elevation = 2.dp,
shape = RoundedCornerShape(12.dp),
modifier = Modifier
.background(CardBackground)
.padding(12.dp)
) {
ProductItem(it) {
// TODO
}
}
}
}
}
}