TextField

Accept text input from the user.

Overview

TextField is a widget that allows users to enter and edit text. It provides features like placeholders, password obscuring, multiline input, and more.

Basic Usage

@Observable class State {
    var text = ""
}

TextField(
    placeholder: "Enter text",
    onChanged: { value in
        state.text = value
    }
)
TextField Examples

With Controller

For programmatic control:

let controller = TextEditingController()

TextField(
    controller: controller,
    placeholder: "Controlled input"
)

// Later: read or set value
print(controller.text)
controller.text = "New value"

Key Parameters

ParameterTypeDescription
placeholderString?Hint text when empty
controllerTextEditingController?Control text programmatically
onChanged(String) -> VoidCalled when text changes
onSubmitted(String) -> VoidCalled when user submits (Enter key)
obscureTextBoolHide text (for passwords)
maxLinesInt?Maximum lines (1 = single line, nil = unlimited)
maxLengthInt?Maximum character count
enabledBoolWhether field is editable
readOnlyBoolShow keyboard but don’t allow edits
autofocusBoolFocus on creation
paddingEdgeInsetsGeometryInternal padding
prefixWidget?Widget before text (icon, etc.)
styleTextStyle?Text style
placeholderStyleTextStyle?Placeholder text style

See Also