Skip to main content

Text Field

A styled single- or multi-line text input field.

When to use it

Use TextField for any free-text input in a form — names, emails, search boxes, or multi-line notes. Supports labels, placeholder text, helper/error messages, and leading and trailing widgets. Either controller or initialValue may be provided, not both.

Import

import 'package:catalyst_ui/catalyst_ui.dart';

Usage

TextField(
label: 'Email',
placeholder: 'you@example.com',
required: true,
onChanged: (v) => setState(() => _email = v),
)

Parameters

ParameterTypeDefaultDescription
labelString?nullAn optional label rendered above the input.
controllerTextEditingController?nullAn optional controller for reading and writing text programmatically.
initialValueString?nullInitial text when no controller is provided.
onChangedValueChanged<String>?nullCalled whenever the text changes.
onSubmittedvoid Function(String)?nullCalled when the user indicates that they are done editing the text in the field.
placeholderString?nullHint text shown when the field is empty.
helperString?nullHelper text shown below the field in the default (non-error) state.
errorString?nullWhen non-null, shows error styling with this message below the field.
leadingWidget?nullAn optional widget at the leading edge (e.g. an icon).
trailingWidget?nullAn optional widget at the trailing edge (e.g. a clear button).
keyboardTypeTextInputType?nullThe keyboard type to use on mobile.
obscureTextboolfalseWhether to obscure the text (e.g. for passwords).
enabledbooltrueWhether the field accepts input.
readOnlyboolfalseWhen true, text is visible but not editable.
requiredboolfalseWhen true, appends a red asterisk to label.
sizeTextFieldSizeTextFieldSize.mediumThe height variant.
focusNodeFocusNode?nullAn optional focus node for programmatic focus control.
textInputActionTextInputAction?nullThe action button shown on the software keyboard.
autocorrectbooltrueWhether autocorrect is enabled.
smartDashesTypeSmartDashesType?nullSmart dashes behaviour on iOS.
smartQuotesTypeSmartQuotesType?nullSmart quotes behaviour on iOS.
maxLinesint?1Maximum number of lines. Pass null for unlimited.
minLinesint?nullMinimum number of lines for a multi-line field.
expandsboolfalseWhen true, the field expands to fill its parent.
autofocusboolfalseWhether to auto-focus on first build.
textCapitalizationTextCapitalizationTextCapitalization.noneControls platform keyboard capitalisation.
inputFormattersList<TextInputFormatter>?nullInput formatters applied on each change.
autofillHintsIterable<String>?[]Autofill hints passed to the platform autofill service.

An assertion enforces that controller and initialValue are not both provided.

Sizes

TextFieldSize values: small (44px), medium (48px, default), large (52px).