Search code examples
androidandroid-jetpack-composeandroid-compose-textfield

Android Jetpack compose (1.0.0-beta07): TextField - None of the following functions can be called with the arguments supplied


I started working with Jetpack compose (1.0.0-beta07) and I ran into a pretty strange problem with TextField. According to all possible documentation and instructions, I do everything right, but Android Studio constantly writes me the message None of the following functions can be called with the arguments supplied. for TextField

Below is my written code, where Studio still underlines Text (label) and text = it, but I take it that it has a problem defining TextField. The problem disappears when I replace remember {mutableStateOf ("text")} with "text", but TextField does not change the text when typing the keyboard.

import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.text.input.KeyboardType

@Composable
fun SimpleTextField(label: String = "Label", key: String = "unknown", keyboardType: KeyboardType = KeyboardType.Text){
    var text = remember {
        mutableStateOf("text")
    }

    TextField(
        value = text,
        onValueChange = {
            text = it
        },
        label = { Text(label) },
        keyboardOptions = KeyboardOptions(keyboardType = keyboardType)
    )
}

Image of error


Solution

  • You can use:

    var text = remember { mutableStateOf("text") }
    
    TextField(
        value = text.value,
        onValueChange = {
            text.value = it
        },
        label = { Text(label) },
        keyboardOptions = KeyboardOptions(keyboardType = keyboardType)
    )
    

    or:

    var text by remember { mutableStateOf("text") }
    
    TextField(
        value = text,
        onValueChange = {
            text = it
        },
        label = { Text(label) },
        keyboardOptions = KeyboardOptions(keyboardType = keyboardType)
    )
    

    You can read more info about the delegated properties in the official doc.