ButtonComponent class Components InteractableComponents

A clickable button component that can be rendered within a terminal-based UI.

The ButtonComponent is an interactive widget that displays a label inside a styled border with customizable colors and padding. It responds to focus, hover, and click events, triggering an action through onPressed.

This component supports multiline labels and adapts its size based on the longest line and provided padding.

Features

  • Customizable background, text, and border colors.
  • Optional border styles via BorderStyle.
  • Responds to hover, focus, and click events.
  • Supports keyboard activation (Enter or Space).

Example

final button = ButtonComponent(
  label: 'Submit',
  onPressed: () {
    print('Button pressed!');
  },
  buttonColor: const ColorRGB(0, 0, 255),
  textColor: const ColorRGB(255, 255, 255),
  outerBorderColor: const ColorRGB(100, 100, 255),
  borderStyle: BorderStyle.thin,
);

See also

Inheritance

Constructors

ButtonComponent.new({required String label, required void onPressed(), AnsiColorType buttonColor = const ColorRGB(0, 0, 0), AnsiColorType outerBorderColor = const ColorRGB(50, 50, 50), AnsiColorType textColor = const ColorRGB(255, 255, 255), BorderStyle borderStyle = BorderStyle.empty, EdgeInsets padding = const EdgeInsets.symmetric(horizontal: 3)})
Creates a new ButtonComponent with the given label and onPressed callback.
const

Properties

borderStyle BorderStyle
The border style applied to the button (e.g., none, single, double).
final
buttonColor AnsiColorType
The background color of the button face.
final
hashCode int
The hash code for this object.
no setterinherited
label String
The text label displayed inside the button.
final
onPressed → void Function()
The callback invoked when the button is pressed.
final
outerBorderColor AnsiColorType
The color of the outer border surrounding the button.
final
padding EdgeInsets
The padding inside the component’s layout bounds.
finalinherited
position Position?
The position of the component within its parent or layout.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
textColor AnsiColorType
The color of the text label.
final

Methods

createInstance() ComponentInstance
Creates a ComponentInstance that can be rendered.
override
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