Skip to content

Instantly share code, notes, and snippets.

@cp-radhika-s
Last active April 5, 2022 10:23
Show Gist options
  • Save cp-radhika-s/ebe2ab119c58d72fbcbb8b00766f2fb3 to your computer and use it in GitHub Desktop.
Save cp-radhika-s/ebe2ab119c58d72fbcbb8b00766f2fb3 to your computer and use it in GitHub Desktop.
@Composable
fun PersonCard(person: Person) {
val foodItems = remember {
mutableStateMapOf<Int, FoodItem>()
}
DropTarget<FoodItem>(
modifier = Modifier
.padding(6.dp)
.width(width = 120.dp)
.fillMaxHeight(0.8f)
) { isInBound, foodItem ->
val bgColor = if (isInBound) Color.Red else Color.White
foodItem?.let {
if (isInBound)
foodItems[foodItem.id] = foodItem
}
Column(
modifier = Modifier.background( bgColor, RoundedCornerShape(16.dp)),
) {
// ...User Image and name Text views
if (foodItems.isNotEmpty()) {
Text(
text = "$${foodItems.values.sumOf { it.price}}",
fontSize = 16.sp,
color = Color.Black,
fontWeight = FontWeight.ExtraBold
)
Text(
text = "${foodItems.size} Items",
fontSize = 14.sp,
color = Color.Black
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment