0% found this document useful (0 votes)
44 views2 pages

E-Commerce App Source Code for Android

Uploaded by

manojkdh30
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views2 pages

E-Commerce App Source Code for Android

Uploaded by

manojkdh30
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

// 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")
}
}
}

You might also like