Hello. I have an OutlinedTextField, Text and Butto...
# compose
a
Hello. I have an OutlinedTextField, Text and Button. In onValueChange I save input value and on Button click call a viewModel method which may result in error, which I show in Text. How can I hide the error Text when onValueChange is triggered once more?
r
Create a Boolean variable and remember it.
val isError by remember { mutableStateOf(false) }
Then show error text if it's true.
if(isError) {
Text(errorText)
}
You can set it to
false
in
onValueChanged
and
true
when there's an error from ViewModel
a
I tried that, but it doesn’t work because there is a variable through which I get the info that viewModel method ended with error and it stays
true
up until the viewModel call is made again.
isError = false
in
onValueChange
happens before it is changed in
if (screenState.isErrorVisible) { isError = true }
resolved by transfer of
isError
in viewModel