CursorModel class

A blinking cursor widget for text input components.

The cursor can be configured to blink, remain static, or be hidden. It follows the Elm Architecture pattern and can be composed into larger text input components.

Example

class TextInputModel implements Model {
  final CursorModel cursor;
  final String text;

  TextInputModel({CursorModel? cursor, this.text = ''})
      : cursor = cursor ?? CursorModel();

  @override
  Cmd? init() => cursor.focus(); // Start blinking

  @override
  (Model, Cmd?) update(Msg msg) {
    // Let cursor handle its messages
    final (newCursor, cmd) = cursor.update(msg);
    return (
      TextInputModel(cursor: newCursor, text: text),
      cmd,
    );
  }

  @override
  String view() => '$text${cursor.view()}';
}
Inheritance

Constructors

CursorModel({Duration blinkSpeed = const Duration(milliseconds: 530), CursorMode mode = CursorMode.blink, String char = ' ', Style? style, Style? textStyle})
Creates a new cursor model.

Properties

blinkSpeed Duration
The speed at which the cursor blinks.
final
char String
The character displayed under the cursor.
no setter
focused bool
Whether the cursor is currently focused.
no setter
hashCode int
The hash code for this object.
no setterinherited
id int
The cursor's unique ID.
no setter
mode CursorMode
The current cursor mode.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
style Style
Style for the cursor itself (when visible).
final
textStyle Style
Style for the text under the cursor.
final
visible bool
Whether the cursor is currently visible (not in blink-off state).
no setter

Methods

blur() CursorModel
Blurs the cursor, stopping the blink animation.
copyWith({Duration? blinkSpeed, CursorMode? mode, String? char, bool? blink, bool? focus, int? blinkTag, Style? style, Style? textStyle}) CursorModel
Creates a copy with the given fields replaced.
focus() → (CursorModel, Cmd?)
Focuses the cursor, starting the blink animation if in blink mode.
init() Cmd?
Returns an optional command to execute on program startup.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setChar(String char) CursorModel
Sets the character displayed under the cursor.
setMode(CursorMode mode) → (CursorModel, Cmd?)
Sets the cursor mode.
toString() String
A string representation of this object.
inherited
update(Msg msg) → (CursorModel, Cmd?)
Updates the component state in response to a message.
override
view() String
Renders the current model state for display.
override

Operators

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