Created
August 31, 2021 02:16
-
-
Save widiarifki/0ffbf4b0047690d8b506811eb8bd33ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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