Skip to content

Instantly share code, notes, and snippets.

@AliAzaz
Last active August 26, 2020 17:10
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 AliAzaz/351715a05408532a26a709f292ac6a8d to your computer and use it in GitHub Desktop.
Save AliAzaz/351715a05408532a26a709f292ac6a8d to your computer and use it in GitHub Desktop.
state approach using
@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