Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.
This repository was archived by the owner on May 7, 2025. It is now read-only.

How to use TextField's error composable #156

Description

@shalva97

Decided to use the TextField's error argument. But the red icon is always visible

How do I use it? my first try was this

TextField(value = server,
    modifier = Modifier.fillMaxWidth(),
    error = {
        if (errors.value is Errors.BadServer) {
            Text(text = "Can not connect to this server")
        }
    },)

That did not work because it checks if the argument is null and then displays red icon. My second try was:

val error = @Composable { if (errors.value is Errors.BadServer) {
    Text(text = "Can not connect to this server")
} else null }

TextField(value = server,
    modifier = Modifier.fillMaxWidth(),
    error = error) // here I get error "The feature "unit conversion" is disabled"

But there I get compilation error. Of course I could duplicate it and wrap whole TextField in if statement, but this feels wrong (lots of arguments will be duplicated). So how can I use it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions