// MainActivity.
kt
package [Link]
import [Link]
import [Link]
import [Link]
import [Link].*
import [Link]
import [Link]
import [Link].material3.*
import [Link].*
import [Link]
import [Link]
data class Product(val id: Int, val name: String, val price: Double)
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
[Link](savedInstanceState)
setContent {
ECommerceApp()
}
}
}
@Composable
fun ECommerceApp() {
var cart by remember { mutableStateOf(listOf<Product>()) }
val products = listOf(
Product(1, "Phone", 299.99),
Product(2, "Laptop", 799.99),
Product(3, "Headphones", 49.99)
)
Column(modifier = [Link]([Link])) {
Text(text = "Products", style = [Link])
Spacer(modifier = [Link]([Link]))
LazyColumn {
items(products) { product ->
ProductItem(product) {
cart = cart + product
}
}
}
Spacer(modifier = [Link]([Link]))
Text(text = "Cart (${[Link]} items)", style =
[Link])
[Link] { item ->
Text(text = "${[Link]} - $${[Link]}")
}
}
}
@Composable
fun ProductItem(product: Product, onAddToCart: () -> Unit) {
Row(modifier = [Link]().padding(vertical = [Link]),
horizontalArrangement = [Link]) {
Column {
Text(text = [Link], style = [Link])
Text(text = "$${[Link]}", style =
[Link])
}
Button(onClick = onAddToCart) {
Text("Add to Cart")
}
}
}