OTPTheme class

Theme configuration for OTP text field styling.

Provides comprehensive styling options for OTP fields including borders, fills, cursors, and state-specific appearances.

Usage

Use preset themes for quick setup:

OTPTextField(
  theme: OTPTheme.light(), // or OTPTheme.dark()
)

Or create custom themes:

OTPTextField(
  theme: OTPTheme.custom(
    borderColor: Colors.grey,
    focusedBorderColor: Colors.blue,
    errorBorderColor: Colors.red,
    fillColor: Colors.white,
    borderRadius: BorderRadius.circular(12),
  ),
)

Modify existing themes using copyWith:

final customTheme = OTPTheme.light().copyWith(
  borderColor: Colors.purple,
  focusedBorderColor: Colors.deepPurple,
);

See also:

  • OTPTextField for the main widget using this theme
  • light for light theme preset
  • dark for dark theme preset
  • custom for creating custom themes

Constructors

OTPTheme({required Color borderColor, required Color focusedBorderColor, Color? errorBorderColor, double errorBorderWidth = 2.0, Color? fillColor, Color? disabledBorderColor, Color? disabledFillColor, double borderWidth = 1.5, double focusedBorderWidth = 2.0, BorderRadius borderRadius = const BorderRadius.all(Radius.circular(8)), double underlineWidth = 2.0, bool showCursor = true, Color? cursorColor, double? cursorHeight, double cursorWidth = 2.0, Color? selectionColor, Color? selectionHandleColor, EdgeInsetsGeometry contentPadding = EdgeInsets.zero})
const

Properties

borderColor → Color
Border color for inactive (unfocused) fields.
final
borderRadius → BorderRadius
Corner radius for field boxes.
final
borderWidth → double
Border width for inactive fields.
final
contentPadding → EdgeInsetsGeometry
Padding inside the text field.
final
cursorColor → Color?
Color of the text cursor.
final
cursorHeight → double?
Height of the text cursor in logical pixels.
final
cursorWidth → double
Width of the text cursor in logical pixels.
final
disabledBorderColor → Color?
Border color when OTPTextField.enabled is false.
final
disabledFillColor → Color?
Background fill color when OTPTextField.enabled is false.
final
errorBorderColor → Color?
Border color when OTPTextField.hasError is true.
final
errorBorderWidth → double
Border width when OTPTextField.hasError is true.
final
fillColor → Color?
Background fill color for the fields.
final
focusedBorderColor → Color
Border color for the currently focused field.
final
focusedBorderWidth → double
Border width for the focused field.
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
selectionColor → Color?
Color of the text selection (highlight color when text is selected/dragged).
final
selectionHandleColor → Color?
Color of the text selection handles.
final
showCursor → bool
Whether to show the text cursor.
final
underlineWidth → double
Line width for OTPFieldStyle.underline style.
final

Methods

copyWith({Color? borderColor, Color? focusedBorderColor, Color? errorBorderColor, double? errorBorderWidth, Color? fillColor, Color? disabledBorderColor, Color? disabledFillColor, double? borderWidth, double? focusedBorderWidth, BorderRadius? borderRadius, double? underlineWidth, bool? showCursor, Color? cursorColor, double? cursorHeight, double? cursorWidth, Color? selectionColor, Color? selectionHandleColor, EdgeInsetsGeometry? contentPadding}) → OTPTheme
Creates a copy of this theme with the given fields replaced.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

custom({required Color borderColor, required Color focusedBorderColor, Color? errorBorderColor, double errorBorderWidth = 2.0, Color? fillColor, Color? disabledBorderColor, Color? disabledFillColor, double borderWidth = 1.5, double focusedBorderWidth = 2.0, BorderRadius borderRadius = const BorderRadius.all(Radius.circular(8)), double underlineWidth = 2.0, bool showCursor = true, Color? cursorColor, double? cursorHeight, double cursorWidth = 2.0, Color? selectionColor, Color? selectionHandleColor, EdgeInsetsGeometry contentPadding = EdgeInsets.zero}) → OTPTheme
Creates a fully customizable theme.
dark({Color? borderColor, Color? focusedBorderColor, Color? errorBorderColor, Color? fillColor, Color? disabledBorderColor, Color? disabledFillColor}) → OTPTheme
Creates a dark theme preset optimized for dark backgrounds.
light({Color? borderColor, Color? focusedBorderColor, Color? errorBorderColor, Color? fillColor, Color? disabledBorderColor, Color? disabledFillColor}) → OTPTheme
Creates a light theme preset optimized for light backgrounds.