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
rajesh
08/24/2021, 10:53 AM
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
Anastasia Rozovskaya
08/24/2021, 12:19 PM
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.
Anastasia Rozovskaya
08/24/2021, 12:31 PM
isError = false
in
onValueChange
happens before it is changed in
if (screenState.isErrorVisible) { isError = true }