TButton class
A customizable button widget with multiple variants, sizes, and states.
TButton provides a comprehensive button solution with support for:
- Multiple visual types (solid, tonal, outline, text, icon)
- Different sizes (xxs, xs, sm, md, lg, block)
- Various shapes (normal, pill, circle)
- Loading states with automatic management
- Active/toggle states
- Icons and images
- Custom theming
Basic Usage
TButton(
text: 'Click Me',
icon: Icons.check,
color: AppColors.primary,
onTap: () => print('Tapped!'),
)
With Loading State
TButton(
text: 'Submit',
loading: true,
onPressed: (options) async {
await performAsyncOperation();
options.stopLoading();
},
)
Toggle Button
TButton(
icon: Icons.favorite_border,
activeIcon: Icons.favorite,
color: Colors.grey,
activeColor: Colors.red,
onChanged: (isActive) => print('Active: $isActive'),
)
See also:
- TButtonTheme for customizing button appearance
- TButtonSize for available size options
- TButtonType for available visual variants
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- TButton
- Available extensions
Constructors
-
TButton({Key? key, TWidgetTheme? baseTheme, TButtonTheme? theme, TButtonShape? shape, TButtonType? type, TButtonSize? size, Color? color, bool loading = false, String loadingText = 'Loading...', IconData? icon, String? imageUrl, String? text, String? tooltip, VoidCallback? onTap, dynamic onPressed(TButtonPressOptions)?, bool active = false, IconData? activeIcon, Color? activeColor, Widget? child, ValueChanged<
bool> ? onChanged, Duration duration = const Duration(milliseconds: 400)}) -
Creates a customizable button widget.
const
Properties
- active → bool
-
Whether the button is in an active state.
final
- activeColor → Color?
-
The color to use when the button is active.
final
- activeIcon → IconData?
-
The icon to display when the button is active.
final
- baseTheme → TWidgetTheme?
-
The base widget theme to use.
final
- child → Widget?
-
A custom child widget to display in the button.
final
- color → Color?
-
The primary color of the button.
final
- duration → Duration
-
The duration for animations (icon changes, color transitions).
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- icon → IconData?
-
The icon to display in the button.
final
- imageUrl → String?
-
The URL of an image to display in the button.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- loading → bool
-
Whether to show a loading indicator when onPressed is called.
final
- loadingText → String
-
The text to display while loading.
final
-
onChanged
→ ValueChanged<
bool> ? -
Callback fired when the button's active state changes.
final
- onPressed → dynamic Function(TButtonPressOptions)?
-
Callback fired when the button is pressed with loading state support.
final
- onTap → VoidCallback?
-
Callback fired when the button is tapped.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- shape → TButtonShape?
-
The shape of the button.
final
- size → TButtonSize?
-
The size configuration for the button.
final
- text → String?
-
The text to display in the button.
final
- theme → TButtonTheme?
-
The theme configuration for this button.
final
- tooltip → String?
-
The tooltip message to show on hover.
final
- type → TButtonType?
-
The visual type/variant of the button.
final
Methods
-
copyWith(
{TButtonTheme? theme, TButtonType? type, Color? color, TButtonSize? size, bool? loading, String? loadingText, IconData? icon, String? text, String? tooltip, VoidCallback? onTap, dynamic onPressed(TButtonPressOptions)?, bool? active, Widget? child}) → TButton -
Available on TButton, provided by the TButtonExtension extension
Creates a copy of the button with updated properties. -
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< TButton> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
estimateWidth(
) → double -
Available on TButton, provided by the TButtonExtension extension
Estimates the width of the button based on its content and size settings. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
custom(
{required Widget child, VoidCallback? onTap, String? tooltip}) → dynamic - Creates a custom button with minimal styling.