https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
d

Dragos Rachieru

09/23/2023, 5:34 PM
Hello, I have a problem with
material3.OutlinedTextField
, the cursor is randomly moved one character left when writing text in it
This happens on
linux_x64
with compose version
1.5.10-beta01
the text of the textfield is actually from a
StateFlow
that is being collected:
Copy code
val state by component.state.collectAsState()

OutlinedTextField(
  value = state.name,
  onValueChange = component::setName,
  label = { Text("Name") },
  isError = !state.isNameValid
)
directly states
At the moment, it is not recommended to use reactive streams to define the state variable for TextField.
with
.collectAsState()
being the given example of what not to do
thank you color 2
b

benkuly

09/24/2023, 8:39 AM
There is a workaound, that works for us:
Copy code
@Composable
fun <T> MutableStateFlow<T>.collectAsStateForTextField() =
    collectAsState(Dispatchers.Main.immediate)
e

ephemient

09/24/2023, 5:31 PM
https://developer.android.com/jetpack/compose/mental-model#parallel there's no guarantee that will continue working
d

Dragos Rachieru

09/27/2023, 8:05 AM
Thank you!