I am trying to:
trailingIcon
of TextField
composable visible only if the user enters some text other than white spaces.trailingIcon
the text in the TextField
should get cleared and the trailingIcon
should disappear.trailingIcon
should appear and enable this text clearing feature.and so on...
I tried searching for solutions to this problem but mostly they were focused on "visible trailingIcons
" and not what I was trying to implement.
Depending on text state you can specify null
or actual view for trailingIcon
parameter:
var text by remember { mutableStateOf("") }
val trailingIconView = @Composable {
IconButton(
onClick = {
text = ""
},
) {
Icon(
Icons.Default.Clear,
contentDescription = "",
tint = Color.Black
)
}
}
TextField(
value = text,
onValueChange = { text = it },
trailingIcon = if (text.isNotBlank()) trailingIconView else null,
)