1

With the code provided in Kotlin documentation, I'm getting the following error when implementing a TextField:

val state = rememberTextFieldState("Initial text", TextRange(0, 12))

TextField(
    state = state,
    lineLimits = TextFieldLineLimits.SingleLine,
    label = { Text("Label") },
)

None of the following candidates is applicable:

fun TextField(value: TextFieldValue, onValueChange: (TextFieldValue) -> Unit, modifier: Modifier = ..., enabled: Boolean = ..., readOnly: Boolean = ..., textStyle: TextStyle = ..., label: @Composable() (() -> Unit)? = ..., placeholder: @Composable() (() -> Unit)? = ..., leadingIcon: @Composable() (() -> Unit)? = ..., trailingIcon: @Composable() (() -> Unit)? = ..., prefix: @Composable() (() -> Unit)? = ..., suffix: @Composable() (() -> Unit)? = ..., supportingText: @Composable() (() -> Unit)? = ..., isError: Boolean = ..., visualTransformation: VisualTransformation = ..., keyboardOptions: KeyboardOptions = ..., keyboardActions: KeyboardActions = ..., singleLine: Boolean = ..., maxLines: Int = ..., minLines: Int = ..., interactionSource: MutableInteractionSource? = ..., shape: Shape = ..., colors: TextFieldColors = ...): Unit
fun TextField(value: String, onValueChange: (String) -> Unit, modifier: Modifier = ..., enabled: Boolean = ..., readOnly: Boolean = ..., textStyle: TextStyle = ..., label: @Composable() (() -> Unit)? = ..., placeholder: @Composable() (() -> Unit)? = ..., leadingIcon: @Composable() (() -> Unit)? = ..., trailingIcon: @Composable() (() -> Unit)? = ..., prefix: @Composable() (() -> Unit)? = ..., suffix: @Composable() (() -> Unit)? = ..., supportingText: @Composable() (() -> Unit)? = ..., isError: Boolean = ..., visualTransformation: VisualTransformation = ..., keyboardOptions: KeyboardOptions = ..., keyboardActions: KeyboardActions = ..., singleLine: Boolean = ..., maxLines: Int = ..., minLines: Int = ..., interactionSource: MutableInteractionSource? = ..., shape: Shape = ..., colors: TextFieldColors = ...): Unit
3
  • What version of the material3 library are you using? You appear to be trying to use a function signature which appears to have been added in 1.4.0-alpha15. Commented Jun 17 at 19:06
  • In the documentation that you linked there is no state or linelimits fields for TextField Commented Jun 17 at 19:06
  • How do I implement 1.4.0? In build.gradle I have this: implementation(libs.androidx.compose.material3) Commented Jun 17 at 20:17

1 Answer 1

2

The TextField that uses a state instead of a value parameter is only available from Material3 version 1.4.0. At the time of writing, however, that is still in alpha (latest stable version is 1.3.2), so you would need to switch to the Alpha BOM of Compose.

Simply replace your dependency

androidx.compose:compose-bom

with this:

androidx.compose:compose-bom-alpha
Sign up to request clarification or add additional context in comments.

2 Comments

As of now, the dependency looks like this:implementation(platform(libs.androidx.compose.bom)). Could you provide the entire implementation? When implementing what you have I get an unresolved type and unsolved reference variable errors.
You apparently use a version catalog, so go there (middle-click on libs.androidx.compose.bom) to append -alpha to the artifact name, as shown in the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.