Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OutlineTextField , TextField not working in Jetpack Compose 1.0.0-alpha02

For some reason, CoreTextField works but TextField and OutlineTextField wont

Works

@Composable
fun TextFieldDemo(){
    val text = remember { mutableStateOf(TextFieldValue("Text")) }
    CoreTextField(modifier = Modifier.fillMaxWidth(),
            value = text.value,
            onValueChange = {text.value = it})
}

Not working

    @Composable
fun TextFieldDemo(){
    val text = remember { mutableStateOf(TextFieldValue("Text")) }
    OutlinedTextField(value = text.value,
            onValueChange = {text.value = it}, label = {Text("Test")})
}

Error: Non of the following Functions can be called for OutlinedTextField

From the docs change

Bug Fixes

androidx.ui.foundation.TextFieldValue and androidx.ui.input.EditorValue are deprecated. TextField, FilledTextField and CoreTextField composables that uses that type is also deprecated. Please use androidx.ui.input.TextFieldValue instead (I4066d, b/155211005)

But I'm using what it says (I think)

Edit

enter image description here

like image 520
SNM Avatar asked Oct 20 '25 13:10

SNM


1 Answers

You are missing the "label" param in the original question, as we can see in the image. Following Gabriele's comment made it work, so you shouldn't change the question with the answer, it's a lot confusing.

Just for the record, here it`s the code that works in 1.0.0-alpha02:

@Composable
fun TextFieldDemo() {
    val text = remember { mutableStateOf(TextFieldValue("Text")) }
    OutlinedTextField(value = text.value,
        onValueChange = { text.value = it },
        label = { Text("Test") })
}
like image 65
Vitor Ramos Avatar answered Oct 23 '25 02:10

Vitor Ramos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!