bottomNavigationBar static method

BottomNavigationBarThemeData bottomNavigationBar({
  1. required ColorScheme colorScheme,
  2. SchemeColor? baseSchemeColor,
  3. SchemeColor? backgroundSchemeColor,
  4. double elevation = kBottomNavigationBarElevation,
  5. double opacity = 1,
  6. int unselectedAlphaBlend = 0x00,
  7. int unselectedAlpha = 0xFF,
  8. BottomNavigationBarLandscapeLayout landscapeLayout = BottomNavigationBarLandscapeLayout.spread,
})

An opinionated BottomNavigationBarThemeData with custom elevation.

Its elevation defaults to kBottomNavigationBarElevation = 0.

The bottom navigation bar uses opinionated colors choices from the passed colorScheme to style the bottom navigation bar.

Background opacity can be set. Unselected items' color, that is background based, can receive a variable blend of primary color using the unselectedAlphaBlend property.

Implementation

static BottomNavigationBarThemeData bottomNavigationBar({
  /// Typically you would pass the same [ColorScheme] that is also used in
  /// your [ThemeData] definition.
  required final ColorScheme colorScheme,

  /// Select which color from the passed in [ColorScheme] to use as base
  /// for the bottom navigation bar's text and icon.
  ///
  /// All colors in the color scheme are not good choices, but some work well.
  ///
  /// If not defined it defaults to primary color. This differs from the
  /// BottomNavigationBar's default theme that uses secondary color.
  /// If you use value [FlexUsedColor.secondary] you get the default design.
  final SchemeColor? baseSchemeColor,

  /// Select which color from the passed in [ColorScheme] to use as background
  /// color for the bottom navigation bar.
  ///
  /// All colors in the color scheme are not good choices, but some work well.
  ///
  /// If not defined it defaults to colorScheme.background color, same as
  /// Flutter default theme.
  final SchemeColor? backgroundSchemeColor,

  /// BottomNavigationBar container elevation.
  ///
  /// Defaults to [kBottomNavigationBarElevation] = 0.
  final double elevation = kBottomNavigationBarElevation,

  /// BottomNavigationBar background opacity.
  ///
  /// Default to 1, fully opaque.
  final double opacity = 1,

  /// The onBackground alpha blend value for unselected item.
  ///
  /// Defaults to 0x00, no blend of primary, use onBackground color as is.
  ///
  /// FlexColorScheme uses value [kUnselectedBackgroundPrimaryAlphaBlend]
  /// = 0x66 when it uses this sub theme.
  final int unselectedAlphaBlend = 0x00,

  /// The alpha value for unselected item.
  ///
  /// Defaults to 0xFF, fully opaque.
  ///
  /// FlexColorScheme uses value [kUnselectedAlphaBlend] = 0xA5 when
  /// it uses this sub theme.
  final int unselectedAlpha = 0xFF,

  /// The arrangement of the bar's [items] when the enclosing
  /// [MediaQueryData.orientation] is [Orientation.landscape].
  ///
  /// The following alternatives are supported:
  ///
  /// * [BottomNavigationBarLandscapeLayout.spread] - the items are
  ///   evenly spaced and spread out across the available width. Each
  ///   item's label and icon are arranged in a column.
  /// * [BottomNavigationBarLandscapeLayout.centered] - the items are
  ///   evenly spaced in a row but only consume as much width as they
  ///   would in portrait orientation. The row of items is centered within
  ///   the available width. Each item's label and icon are arranged
  ///   in a column.
  /// * [BottomNavigationBarLandscapeLayout.linear] - the items are
  ///   evenly spaced and each item's icon and label are lined up in a
  ///   row instead of a column.
  ///
  /// Defaults to [BottomNavigationBarLandscapeLayout.spread].
  final BottomNavigationBarLandscapeLayout landscapeLayout =
      BottomNavigationBarLandscapeLayout.spread,
}) {
  // Get item base color, defaults to primary.
  final Color _baseColor = baseSchemeColor == null
      ? colorScheme.primary
      : schemeColor(baseSchemeColor, colorScheme);
  // Get bottom bar background, defaults to background.
  final Color _backgroundColor = backgroundSchemeColor == null
      ? colorScheme.background
      : schemeColor(backgroundSchemeColor, colorScheme);
  // Get the on color pair for the chosen background color.
  final Color _backgroundOnColor = schemeColorPair(
      backgroundSchemeColor ?? SchemeColor.background, colorScheme);
  return BottomNavigationBarThemeData(
    elevation: elevation,
    backgroundColor: _backgroundColor.withOpacity(opacity),
    landscapeLayout: landscapeLayout,
    selectedItemColor: _baseColor,
    selectedIconTheme: IconThemeData(
      color: _baseColor,
    ),
    unselectedItemColor: _backgroundOnColor
        .blendAlpha(_baseColor, unselectedAlphaBlend)
        .withAlpha(unselectedAlpha),
    unselectedIconTheme: IconThemeData(
      color: _backgroundOnColor
          .blendAlpha(_baseColor, unselectedAlphaBlend)
          .withAlpha(unselectedAlpha),
    ),
  );
}