TabView class
A tabbed interface for displaying multiple pages of content.
TabView provides a familiar tab-based navigation pattern, similar to browser tabs. Users can switch between tabs, and optionally rearrange, open, or close tabs.
Managing tabs
A TabViewController owns the tabs and selection, and notifies this widget when they change. Create it once in a State.initState method and dispose it in State.dispose.
A close action only invokes the selected Tab.onClosed callback; it never removes the tab automatically. The callback must remove the tab from the controller. A tab without Tab.onClosed cannot be closed.
Give tabs stable, unique keys when their order or membership can change. Keys preserve a tab body's state when tabs are recreated or reordered. Unkeyed tabs can retain state when the same Tab instances are reused, but reordering newly created, otherwise indistinguishable unkeyed tabs is ambiguous and state can follow their previous positions instead.

{@tool snippet} This short controller lifecycle example adds and closes tabs:
class _TabViewExampleState extends State<TabViewExample> {
late final TabViewController controller;
var nextDocument = 2;
@override
void initState() {
super.initState();
controller = TabViewController(tabs: [_tab('Document 1')]);
}
Tab _tab(String title) {
final key = ValueKey(title);
return Tab(
key: key,
text: Text(title),
body: Center(child: Text(title)),
onClosed: () => controller.removeAt(
controller.tabs.indexWhere((tab) => tab.key == key),
),
);
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => TabView(
controller: controller,
onNewPressed: () => controller.add(_tab('Document ${nextDocument++}')),
);
}
{@end-tool}
Keyboard shortcuts
When shortcutsEnabled is true, the following shortcuts are available:
Ctrl + T- Create a new tab (if onNewPressed is provided)Ctrl + WorCtrl + F4- Close the current tabCtrl + 1-8- Navigate to tabs 1-8Ctrl + 9- Navigate to the last tab
See also:
- NavigationView, for top-level app navigation
- Tab, the individual tab widget
- learn.microsoft.com/en-us/windows/apps/design/controls/tab-view
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- TabView
Constructors
-
TabView({required TabViewController controller, Key? key, ValueChanged<
int> ? onChanged, VoidCallback? onNewPressed, Widget newTabIcon = const WindowsIcon(WindowsIcons.add, fallbackIcon: FluentIcons.add), bool shortcutsEnabled = true, ReorderCallback? onReorder, bool showScrollButtons = true, ScrollPosController? scrollController, double minTabWidth = _kMinTileWidth, double maxTabWidth = _kMaxTileWidth, CloseButtonVisibilityMode closeButtonVisibility = CloseButtonVisibilityMode.always, TabWidthBehavior tabWidthBehavior = TabWidthBehavior.equal, Widget? header, double? reservedStripWidth, Widget stripBuilder(BuildContext context, Widget strip)?, Duration closeDelayDuration = const Duration(seconds: 1), bool automaticallyKeepAlive = true}) -
Creates a tab view.
const
Properties
- automaticallyKeepAlive → bool
-
Whether visited tab bodies are automatically kept alive offscreen.
final
- closeButtonVisibility → CloseButtonVisibilityMode
-
Indicates the close button visibility mode.
final
- closeDelayDuration → Duration
-
The delay duration to animate the tab after it's closed. Only applied when
tabWidthBehavior is TabWidthBehavior.equal.
final
- controller → TabViewController
-
Controls the tabs and selected tab.
final
-
Displayed after all the tabs and buttons.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- header → Widget?
-
Displayed before all the tabs and buttons.
final
- isReorderEnabled → bool
-
Whether reordering is enabled.
no setter
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- maxTabWidth → double
-
The max width a tab can have. Must not be negative.
final
- minTabWidth → double
-
The min width a tab can have. Must not be negative.
final
- newTabIcon → Widget
-
The icon of the "Add new tab" button.
final
-
onChanged
→ ValueChanged<
int> ? -
Called after the user selects a tab.
final
- onNewPressed → VoidCallback?
-
Called when the user requests a new tab by pressing the new-tab button or
using the
Ctrl + Tshortcut.final - onReorder → ReorderCallback?
-
Called when the user requests that a tab move from
oldIndextonewIndex.final - reservedStripWidth → double?
-
The minimum width reserved at the end of the tab strip.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scrollController → ScrollPosController?
-
The ScrollPosController used to move TabView to right and left when the
tabs don't fit the available horizontal space.
final
- shortcutsEnabled → bool
-
Whether the following shortcuts are enabled:
final
- showNewButton → bool
-
Whenever the new button should be displayed.
no setter
- showScrollButtons → bool
-
Whether the buttons that scroll forward or backward
should be displayed, if necessary.
final
- stripBuilder → Widget Function(BuildContext context, Widget strip)?
-
The builder for the strip that contains the tabs.
final
- tabWidthBehavior → TabWidthBehavior
-
Indicates how a tab will size itself.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< StatefulWidget> -
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.
override
-
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