CupertinoTabBar class Null safety

An iOS-styled bottom navigation tab bar.

Displays multiple tabs using BottomNavigationBarItem with one tab being active, the first tab by default.

This StatelessWidget doesn't store the active tab itself. You must listen to the onTap callbacks and call setState with a new currentIndex for the new selection to reflect. This can also be done automatically by wrapping this with a CupertinoTabScaffold.

Tab changes typically trigger a switch between Navigators, each with its own navigation stack, per standard iOS design. This can be done by using CupertinoTabViews inside each tab builder in CupertinoTabScaffold.

If the given backgroundColor's opacity is not 1.0 (which is the case by default), it will produce a blurring effect to the content behind it.

When used as CupertinoTabScaffold.tabBar, by default CupertinoTabBar has its text scale factor set to 1.0 and does not respond to text scale factor changes from the operating system, to match the native iOS behavior. To override this behavior, wrap each of the navigationBar's components inside a MediaQuery with the desired MediaQueryData.textScaleFactor value. The text scale factor value from the operating system can be retrieved in many ways, such as querying MediaQuery.textScaleFactorOf against CupertinoApp's BuildContext.

This example shows a CupertinoTabBar placed in a CupertinoTabScaffold.
To create a local project with this code sample, run:
flutter create --sample=cupertino.CupertinoTabBar.1 mysample

See also:

Inheritance
Implemented types

Constructors

CupertinoTabBar({Key? key, required List<BottomNavigationBarItem> items, ValueChanged<int>? onTap, int currentIndex = 0, Color? backgroundColor, Color? activeColor, Color inactiveColor = _kDefaultTabBarInactiveColor, double iconSize = 30.0, double height = _kTabBarHeight, Border? border = const Border(top: BorderSide(color: _kDefaultTabBarBorderColor, width: 0.0))})
Creates a tab bar in the iOS style.
const

Properties

activeColor Color?
The foreground color of the icon and title for the BottomNavigationBarItem of the selected tab.
final
backgroundColor Color?
The background color of the tab bar. If it contains transparency, the tab bar will automatically produce a blurring effect to the content behind it.
final
border Border?
The border of the CupertinoTabBar.
final
currentIndex int
The index into items of the current active item.
final
hashCode int
The hash code for this object.
nonVirtual">@nonVirtualread-onlyinherited
height double
The height of the CupertinoTabBar.
final
iconSize double
The size of all of the BottomNavigationBarItem icons.
final
inactiveColor Color
The foreground color of the icon and title for the BottomNavigationBarItems in the unselected state.
final
items List<BottomNavigationBarItem>
The interactive items laid out within the bottom navigation bar.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onTap ValueChanged<int>?
The callback that is called when a item is tapped.
final
preferredSize Size
The size this widget would prefer if it were otherwise unconstrained.
read-onlyoverride
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
copyWith({Key? key, List<BottomNavigationBarItem>? items, Color? backgroundColor, Color? activeColor, Color? inactiveColor, double? iconSize, double? height, Border? border, int? currentIndex, ValueChanged<int>? onTap}) CupertinoTabBar
Create a clone of the current CupertinoTabBar but with provided parameters overridden.
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
protected">@protectedinherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
opaque(BuildContext context) bool
Indicates whether the tab bar is fully opaque or can have contents behind it show through it.
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}) 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.
nonVirtual">@nonVirtualinherited