CustomBottomNavigationBar constructor
- Key? key,
- required List<
BottomNavigationBarItem> items, - ValueChanged<
int> ? onTap, - int currentIndex = 0,
- double? elevation,
- BottomNavigationBarType? type,
- Color? fixedColor,
- Color? backgroundColor,
- double iconSize = 24.0,
- Color? selectedItemColor,
- Color? unselectedItemColor,
- IconThemeData? selectedIconTheme,
- IconThemeData? unselectedIconTheme,
- double selectedFontSize = 14.0,
- double unselectedFontSize = 12.0,
- TextStyle? selectedLabelStyle,
- TextStyle? unselectedLabelStyle,
- bool? showSelectedLabels,
- bool? showUnselectedLabels,
- MouseCursor? mouseCursor,
Creates a bottom navigation bar which is typically used as a Scaffold's Scaffold.bottomNavigationBar argument.
The length of items must be at least two and each item's icon and label
must not be null.
If type is null then BottomNavigationBarType.fixed is used when there
are two or three items, BottomNavigationBarType.shifting otherwise.
The iconSize, selectedFontSize, unselectedFontSize, and elevation
arguments must be non-null and non-negative.
If selectedLabelStyle.color and unselectedLabelStyle.color values
are non-null, they will be used instead of selectedItemColor and
unselectedItemColor.
If custom IconThemeDatas are used, you must provide both
selectedIconTheme and unselectedIconTheme, and both
IconThemeData.color and IconThemeData.size must be set.
If both selectedLabelStyle.fontSize and selectedFontSize are set,
selectedLabelStyle.fontSize will be used.
Only one of selectedItemColor and fixedColor can be specified. The
former is preferred, fixedColor only exists for the sake of
backwards compatibility.
If showSelectedLabels is null, BottomNavigationBarThemeData.showSelectedLabels
is used. If BottomNavigationBarThemeData.showSelectedLabels is null,
then showSelectedLabels defaults to true.
If showUnselectedLabels is null, BottomNavigationBarThemeData.showUnselectedLabels
is used. If BottomNavigationBarThemeData.showSelectedLabels is null,
then showUnselectedLabels defaults to true when type is
BottomNavigationBarType.fixed and false when type is
BottomNavigationBarType.shifting.
Implementation
CustomBottomNavigationBar({
Key? key,
required this.items,
this.onTap,
this.currentIndex = 0,
this.elevation,
this.type,
Color? fixedColor,
this.backgroundColor,
this.iconSize = 24.0,
Color? selectedItemColor,
this.unselectedItemColor,
this.selectedIconTheme,
this.unselectedIconTheme,
this.selectedFontSize = 14.0,
this.unselectedFontSize = 12.0,
this.selectedLabelStyle,
this.unselectedLabelStyle,
this.showSelectedLabels,
this.showUnselectedLabels,
this.mouseCursor,
}) : assert(items != null),
assert(items.length >= 2),
assert(
items.every((BottomNavigationBarItem item) => item.title != null) ||
items.every((BottomNavigationBarItem item) => item.label != null),
'Every item must have a non-null title or label',
),
assert(0 <= currentIndex && currentIndex < items.length),
assert(elevation == null || elevation >= 0.0),
assert(iconSize != null && iconSize >= 0.0),
assert(
selectedItemColor == null || fixedColor == null,
'Either selectedItemColor or fixedColor can be specified, but not both'
),
assert(selectedFontSize != null && selectedFontSize >= 0.0),
assert(unselectedFontSize != null && unselectedFontSize >= 0.0),
selectedItemColor = selectedItemColor ?? fixedColor,
super(key: key);