Skip to main content
The ChromiaTextField provides a consistent text input experience with support for validation, icons, labels, and more.

Basic Usage

import 'package:chromia_ui/chromia_ui.dart';

ChromiaTextField(
  label: 'Email',
  hintText: 'Enter your email',
  onChanged: (value) => print(value),
)

Variants

Text fields come in two variants:

Filled (Default)

Text field with background fill.
ChromiaTextField(
  variant: ChromiaTextFieldVariant.filled,
  label: 'Username',
  hintText: 'Enter username',
)

Outlined

Text field with border and transparent background.
ChromiaTextField(
  variant: ChromiaTextFieldVariant.outlined,
  label: 'Username',
  hintText: 'Enter username',
)

Sizes

Text fields support three size options:
// Small
ChromiaTextField(
  size: ChromiaTextFieldSize.small,
  hintText: 'Small field',
)

// Medium (default)
ChromiaTextField(
  size: ChromiaTextFieldSize.medium,
  hintText: 'Medium field',
)

// Large
ChromiaTextField(
  size: ChromiaTextFieldSize.large,
  hintText: 'Large field',
)

With Icons

Add prefix or suffix icons:
ChromiaTextField(
  label: 'Search',
  prefixIcon: Icon(Icons.search),
  hintText: 'Search...',
)

ChromiaTextField(
  label: 'Password',
  suffixIcon: Icon(Icons.visibility),
  obscureText: true,
)

With Prefix/Suffix Text

ChromiaTextField(
  label: 'Website',
  prefixText: 'https://',
  hintText: 'example.com',
)

ChromiaTextField(
  label: 'Price',
  prefixText: '\$',
  suffixText: 'USD',
  keyboardType: TextInputType.number,
)

Validation

Use built-in validators for form validation:
ChromiaTextField(
  label: 'Email',
  validators: [
    RequiredValidator('Email is required'),
    EmailValidator('Please enter a valid email'),
  ],
  onChanged: (value) {},
)

Available Validators

  • RequiredValidator - Ensures the field is not empty
  • EmailValidator - Validates email format
  • EqualsValidator - Ensures value equals a comparison value
  • DifferentValidator - Ensures value differs from a comparison value
// Password confirmation example
ChromiaTextField(
  label: 'Confirm Password',
  obscureText: true,
  validators: [
    RequiredValidator('Please confirm your password'),
    EqualsValidator(
      'Passwords do not match',
      compareValue: passwordController.text,
    ),
  ],
)

Error State

Display error messages:
ChromiaTextField(
  label: 'Username',
  errorText: 'Username is already taken',
)

Helper Text

Show helpful information below the field:
ChromiaTextField(
  label: 'Bio',
  helperText: 'Tell us about yourself',
  maxLines: 4,
)

Character Counter

Automatically shows character count with max length:
ChromiaTextField(
  label: 'Tweet',
  maxLength: 280,
  helperText: 'Share your thoughts',
)

Multiline Text

Create a textarea with multiple lines:
ChromiaTextField(
  label: 'Description',
  maxLines: 5,
  minLines: 3,
  hintText: 'Enter description',
)

Password Field

Create a password input field:
ChromiaTextField(
  label: 'Password',
  obscureText: true,
  suffixIcon: Icon(Icons.visibility_off),
)

Read-Only

Make the field read-only:
ChromiaTextField(
  label: 'ID',
  initialValue: 'USER-12345',
  readOnly: true,
)

Disabled

Disable the text field:
ChromiaTextField(
  label: 'Email',
  initialValue: '[email protected]',
  enabled: false,
)

Keyboard Types

// Email keyboard
ChromiaTextField(
  label: 'Email',
  keyboardType: TextInputType.emailAddress,
)

// Number keyboard
ChromiaTextField(
  label: 'Phone',
  keyboardType: TextInputType.phone,
)

// URL keyboard
ChromiaTextField(
  label: 'Website',
  keyboardType: TextInputType.url,
)

Input Formatters

Restrict input with formatters:
import 'package:flutter/services.dart';

ChromiaTextField(
  label: 'Age',
  keyboardType: TextInputType.number,
  inputFormatters: [
    FilteringTextInputFormatter.digitsOnly,
    LengthLimitingTextInputFormatter(3),
  ],
)

Controller

Control the text field programmatically:
final controller = TextEditingController();

ChromiaTextField(
  controller: controller,
  label: 'Username',
)

// Clear the field
controller.clear();

// Set value
controller.text = 'new value';

Parameters

controller
TextEditingController?
Controls the text being edited.
focusNode
FocusNode?
Defines the focus for this text field.
initialValue
String?
Initial value for the text field.
label
String?
The label text displayed above the field.
hintText
String?
The hint text displayed when the field is empty.
helperText
String?
Helper text displayed below the field.
errorText
String?
Error text displayed below the field.
prefixIcon
Widget?
Icon displayed at the start of the field.
suffixIcon
Widget?
Icon displayed at the end of the field.
prefixText
String?
Text displayed before the input.
suffixText
String?
Text displayed after the input.
obscureText
bool
default:"false"
Whether to obscure the text (for passwords).
enabled
bool
default:"true"
Whether the field is enabled.
readOnly
bool
default:"false"
Whether the field is read-only.
maxLines
int
default:"1"
Maximum number of lines.
minLines
int?
Minimum number of lines.
maxLength
int?
Maximum length of input.
keyboardType
TextInputType?
The type of keyboard to show.
textInputAction
TextInputAction?
The action button on the keyboard.
textCapitalization
TextCapitalization
default:"none"
How to capitalize text.
autocorrect
bool
default:"true"
Whether to enable autocorrect.
enableSuggestions
bool
default:"true"
Whether to show suggestions.
autofocus
bool
default:"false"
Whether to autofocus on this field.
validators
List<ChromiaTextFieldValidator>
default:"[]"
List of validators to apply.
inputFormatters
List<TextInputFormatter>?
Input formatters to restrict input.
onChanged
ValueChanged<String>?
Called when the text changes.
onSubmitted
ValueChanged<String>?
Called when the user submits.
onTap
VoidCallback?
Called when the field is tapped.
onEditingComplete
VoidCallback?
Called when editing is complete.
variant
ChromiaTextFieldVariant
default:"filled"
The text field variant. Options: filled, outlined.
size
ChromiaTextFieldSize
default:"medium"
The text field size. Options: small, medium, large.
style
ChromiaTextFieldStyle?
Custom style to override defaults.

Build docs developers (and LLMs) love