Home > other >  Jetpack Compose TextField arguments list; color not allowed
Jetpack Compose TextField arguments list; color not allowed

Time:03-27

For some reason when trying to make a TextField in Compose I am constantly running into problems with the parameters, for intance:

// this is perfectly fine
@Composable
fun Username() {
val emailState = remember{ mutableStateOf(TextFieldValue())}
TextField(
    modifier = Modifier.fillMaxWidth(),
    label = { Text(text = stringResource(R.string.username_label))},
    value = emailState.value,
    onValueChange = { emailState.value = it },
    shape = RoundedCornerShape(8.dp),
    keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Email),
    )
}

if i try to insert a colours value however, everything falls apart:

@Composable
fun Username() {
val emailState = remember{ mutableStateOf(TextFieldValue())}
TextField(
    modifier = Modifier.fillMaxWidth(),
    label = { Text(text = stringResource(R.string.username_label))},
    value = emailState.value,
    onValueChange = { emailState.value = it },
    shape = RoundedCornerShape(8.dp),
    keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Email),
    color = TextFieldDefaults.textFieldColors(
        unfocusedIndicatorColor = Color.Transparent,
        focusedIndicatorColor = Color.Transparent
        )
    )
}

regardless of where I add 'color' within the arguments list here it won't work. I get back this:

None of the following functions can be called with the arguments supplied.

I don't understand the Constructor here at all, I have even changed my code to be more similar to others online and still get the same error.

Compose version is 1.0.2

CodePudding user response:

TextField has no color parameter. you must use colors instead

  • Related