TabBar class
A horizontal tab bar widget to select active views from a tab set.
Keyboard Bindings
[: Swaps the active tab index backward (decreases index, wraps around).]: Swaps the active tab index forward (increases index, wraps around).Shift + Tab(orbacktab): Swaps the active tab index backward.
Lifecycle and Listener Cleanup
If a WindowManager is provided to bind global keys, this widget adds a listener to intercept tab commands. To prevent memory leaks, you must call dispose when this widget is removed from the tree to clean up the key listener registration.
Example Usage
final controller = TabController(length: 3);
final tabBar = TabBar(
controller: controller,
labels: const ['General', 'Settings', 'About'],
windowManager: myWindowManager,
);
// Clean up later when the view changes:
tabBar.dispose();
Properties and Settings
| Property | Type | Description |
|---|---|---|
controller |
TabController | Coordinates the active tab index. |
labels |
List<String> | Text labels for each tab. |
windowManager |
WindowManager? | Window manager to bind global hotkeys. |
activeStyle |
Style | Style of the selected tab. |
inactiveStyle |
Style | Style of the unselected tabs. |
Constructors
-
TabBar({required TabController controller, required List<
String> labels, WindowManager? windowManager, Style activeStyle = const Style(foreground: CharmColors.charple, modifiers: Modifier.bold), Style inactiveStyle = const Style(foreground: CharmColors.squid, modifiers: Modifier.dim)}) - Creates a TabBar.
Properties
- activeStyle → Style
-
Style of the selected tab.
final
- controller → TabController
-
Coordinates the active tab index.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- inactiveStyle → Style
-
Style of the unselected tabs.
final
- key → Key?
-
The optional key for this widget.
finalinherited
-
labels
→ List<
String> -
Text labels for each tab.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- windowManager → WindowManager?
-
Window manager to bind global hotkeys.
final
Methods
-
createElement(
) → Element -
Creates an Element to manage this widget's location in the tree.
inherited
-
dispose(
) → void - Cleans up registered global key listeners from the windowManager.
-
getIntrinsicHeight(
int width) → int -
Computes the intrinsic height of this widget under the given
widthconstraint.inherited -
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
bufferwithin the specifiedarea.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited