Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save widiarifki/0ffbf4b0047690d8b506811eb8bd33ed to your computer and use it in GitHub Desktop.
Save widiarifki/0ffbf4b0047690d8b506811eb8bd33ed to your computer and use it in GitHub Desktop.
@Composable
fun FormInputContainer(
onAddItem: (ShoppingItem) -> Unit
) {
var newItem by remember { mutableStateOf("") }
val focusManager = LocalFocusManager.current
Row(
modifier = Modifier
.fillMaxWidth(1f)
.height(IntrinsicSize.Min)
.padding(8.dp)
) {
// Field input
TextField(
label = { Text("Item belanja baru") },
singleLine = true,
onValueChange = { newItem = it },
value = newItem
)
// Margin / spacer
Spacer(modifier = Modifier.width(8.dp))
// Button add item
Button(
enabled = newItem.isNotBlank(),
onClick = {
onAddItem(ShoppingItem(name = newItem))
newItem = ""
focusManager.clearFocus()
},
modifier = Modifier.fillMaxHeight()
) {
Text(text = "Tambah")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment