Button class

An interactive TUI button widget that triggers a callback when activated.

Interfaces

  • Keyboard: When focused is true, pressing Space (' '), Enter ('\n'), or Carriage Return ('\r') will trigger onPressed.
  • Mouse: Left-clicking (mouse press event) inside the bounds of the button triggers onPressed.

Example Usage

Button(
  text: 'Submit',
  focused: true,
  onPressed: () {
    print('Button clicked!');
  },
);

Properties and Styling

Property Type Description
text String Label displayed on the button.
onPressed void Function() Callback executed when activated.
focused bool Whether this button currently has keyboard focus.
style Style Normal rendering style.
focusedStyle Style Rendering style applied when focused is true.
Inheritance
Implemented types

Constructors

Button({required String text, required void onPressed(), bool focused = false, Style style = Style.empty, Style focusedStyle = const Style(modifiers: Modifier.reverse)})
Creates a new Button.
const

Properties

focused bool
Whether this button currently has keyboard focus.
final
focusedStyle Style
The rendering style applied when the button is focused.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
The optional key for this widget.
finalinherited
onPressed → void Function()
The callback executed when the button is activated.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
style Style
The normal rendering style.
final
text String
The text label displayed on the button.
final

Methods

createElement() Element
Creates an Element to manage this widget's location in the tree.
inherited
getIntrinsicHeight(int width) int
Computes the intrinsic height of this widget under the given width constraint.
inherited
handleKeyEvent(KeyEvent event) bool
Handles key activations (Space or Enter).
override
handleMouseEvent(MouseEvent event, int localX, int localY) → void
Handles mouse clicks.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
render(Buffer buffer, Rect area) → void
Renders the widget onto the provided buffer within the specified area.
override
toString() String
A string representation of this object.
inherited

Operators

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