Last active
August 26, 2020 17:10
-
-
Save AliAzaz/351715a05408532a26a709f292ac6a8d to your computer and use it in GitHub Desktop.
state approach using
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 AddTask() { | |
val title = remember { mutableStateOf("") } | |
val titleExist = remember { mutableStateOf(false) } | |
if (titleExist.value) Text( | |
modifier = Modifier.padding(5.dp), | |
text = "Title already exist", | |
style = TextStyle(color = Color(0xFFF50B0B)) + MaterialTheme.typography.body1 | |
) | |
TextField( | |
value = title.value, | |
onValueChange = { item -> | |
title.value = item | |
titleExist.value = isTitleExist(title) | |
}, | |
label = { | |
Text( | |
modifier = Modifier.padding(5.dp), | |
text = "Title of Task", | |
style = TextStyle(color = Color(0x77666666)) + MaterialTheme.typography.h6 | |
) | |
}, | |
modifier = Modifier.fillMaxWidth(), | |
textStyle = MaterialTheme.typography.h6, | |
backgroundColor = Color.White | |
) | |
} | |
fun isTitleExist(title: MutableState<TextFieldValue>): Boolean { | |
val item = AppMain.taskList.find { it.title == title.value.text.trim() } | |
return item != null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment