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

4

17

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

Arin answered 20/5, 2021 at 9:45 Comment(0)
H
5

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.

Hoffarth answered 20/5, 2021 at 9:57 Comment(4)
This solution is what I was looking for.Goles
Unfortunately, the error is still present: var text by remember { mutableStateOf("Text") } TextField( modifier = Modifier.fillMaxWidth(), value = text, onValueChange = { value -> text = value }, label = Text("Label"), keyboardType = KeyboardType.Text )Afflictive
Compose 1.0.0-rc02Afflictive
This is still a known issue in 2023. Is there a fix?Rockhampton
W
1

I have the same error. And I change the build.gradle.kts file imports and activity imports. Its work fine now.

in graddle I add the:

dependencies {
    val composeVersion = "1.4.2"
    implementation("androidx.compose.material:material:$composeVersion")
}

In activity or composable file Text import should be like:

import androidx.compose.material.Text

enter image description here

Welfarism answered 27/3 at 10:52 Comment(0)
T
0

Try to check some parameters for example color is using material3 in the latest version so they need the parameter according to that

in my case, this line is causing errors in the field

    colors = MaterialTheme.color scheme.background

so I replace it with the below one

    colors = TextFieldDefaults.outlinedTextFieldColors(),
Terrify answered 1/6, 2023 at 15:30 Comment(0)
T
0

I faced a similar issue and resolved it by adding @OptIn(ExperimentalMaterial3Api::class) above the Compose function.

Tic answered 4/2 at 8:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.