2

Using TextField in Compose, I found that looks like a bug. When I change the textfield value , focus out and in again, onValuseChange method is called even there is no change. this is not What I want, So I write some defending code for this comparing prev value. But I want to know another nice solution. here is my code.

onValueChange = { _inputText ->
               
                if(_inputText.text != countState.value){
                   
                }
            },
Charles
  • 93
  • 7

2 Answers2

0

If you are using onValueChange: (TextFieldValue) -> Unit callback, it will be called when you focus or unfocus TextField. This is because focus puts cursor into TextField and it's state is saved into TextFieldValue.

Vygintas B
  • 1,624
  • 13
  • 31
0

Use interactionSource parameter that keeps track of the interaction track of the TextField and you can apply it to detect when the Text changes due to user interaction.

Harsh Panchal
  • 146
  • 1
  • 1
  • 6