Skip to content

Instantly share code, notes, and snippets.

@maq796113
Created June 4, 2024 13:35
Show Gist options
  • Save maq796113/da2dcbf69ca7d792d6cb42ee45ade19f to your computer and use it in GitHub Desktop.
Save maq796113/da2dcbf69ca7d792d6cb42ee45ade19f to your computer and use it in GitHub Desktop.
@Composable
fun GridCellTable(
ingredientState: IngredientState
) {
val items = mutableListOf<IngredientState>()
Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp)
) {
Row(
modifier = Modifier
.fillMaxWidth()
.background(Peach)
.padding(8.dp)
) {
Text("Items", modifier = Modifier.weight(1f))
Text("Quantity", modifier = Modifier.weight(1f))
Text("Weight", modifier = Modifier.weight(1f))
}
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 8.dp)
) {
RuniqueTextField(
state = ingredientState.name,
startIcon = null,
endIcon = null,
hint = "Item",
title = null,
modifier = Modifier.weight(1f)
)
RuniqueTextField(
state = ingredientState.amount,
startIcon = null,
endIcon = null,
hint = "Amount",
title = null,
modifier = Modifier.weight(1f)
)
RuniqueTextField(
state = ingredientState.unit,
startIcon = null,
endIcon = null,
hint = "Unit",
title = null,
modifier = Modifier.weight(1f)
)
}
}
Spacer(modifier = Modifier.height(16.dp))
LazyColumn {
items(items) { item ->
Row(
modifier = Modifier
.fillMaxWidth()
.padding(
vertical = 8.dp
)
) {
Text(
item.name.text.toString(), modifier = Modifier.weight(1f)
)
Text(
"here", modifier = Modifier.weight(1f), color = Color.White
)
Text(
item.amount.text.toString(), modifier = Modifier.weight(1f)
)
Text(
item.unit.text.toString(), modifier = Modifier.weight(1f)
)
}
}
}
Spacer(modifier = Modifier.height(16.dp))
Button(
onClick = {
//append the entry to items
items.add(
ingredientState
)
//reset the state
},
colors = ButtonColors(
containerColor = Peach,
contentColor = Color.White,
disabledContainerColor = Color.Gray,
disabledContentColor = Color.White
)
) {
Text("➕ Add Item")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment