bottom_navigation_bar_item.dart 3.02 KB
Newer Older
xster's avatar
xster committed
1 2 3 4 5 6 7 8 9 10 11
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:ui' show Color;

import 'framework.dart';

/// An interactive button within either material's [BottomNavigationBar]
/// or the iOS themed [CupertinoTabBar] with an icon and title.
///
12 13
/// This class is rarely used in isolation. It is typically embedded in one of
/// the bottom navigation widgets above.
xster's avatar
xster committed
14 15 16 17
///
/// See also:
///
///  * [BottomNavigationBar]
18
///  * <https://material.io/design/components/bottom-navigation.html>
xster's avatar
xster committed
19
///  * [CupertinoTabBar]
20
///  * <https://developer.apple.com/ios/human-interface-guidelines/bars/tab-bars>
xster's avatar
xster committed
21 22 23
class BottomNavigationBarItem {
  /// Creates an item that is used with [BottomNavigationBar.items].
  ///
24
  /// The argument [icon] should not be null and the argument [title] should not be null when used in a Material Design's [BottomNavigationBar].
xster's avatar
xster committed
25 26
  const BottomNavigationBarItem({
    @required this.icon,
27
    this.title,
28
    Widget activeIcon,
xster's avatar
xster committed
29
    this.backgroundColor,
30
  }) : activeIcon = activeIcon ?? icon,
31
       assert(icon != null);
xster's avatar
xster committed
32 33 34 35 36 37

  /// The icon of the item.
  ///
  /// Typically the icon is an [Icon] or an [ImageIcon] widget. If another type
  /// of widget is provided then it should configure itself to match the current
  /// [IconTheme] size and color.
38 39 40 41 42 43 44 45 46 47 48 49
  ///
  /// If [activeIcon] is provided, this will only be displayed when the item is
  /// not selected.
  ///
  /// To make the bottom navigation bar more accessible, consider choosing an
  /// icon with a stroked and filled version, such as [Icons.cloud] and
  /// [Icons.cloud_queue]. [icon] should be set to the stroked version and
  /// [activeIcon] to the filled version.
  ///
  /// If a particular icon doesn't have a stroked or filled version, then don't
  /// pair unrelated icons. Instead, make sure to use a
  /// [BottomNavigationBarType.shifting].
xster's avatar
xster committed
50 51
  final Widget icon;

52 53 54 55 56 57 58 59
  /// An alternative icon displayed when this bottom navigation item is
  /// selected.
  ///
  /// If this icon is not provided, the bottom navigation bar will display
  /// [icon] in either state.
  ///
  /// See also:
  ///
60
  ///  * [BottomNavigationBarItem.icon], for a description of how to pair icons.
61 62
  final Widget activeIcon;

63
  /// The title of the item. If the title is not provided only the icon will be shown when not used in a Material Design [BottomNavigationBar].
xster's avatar
xster committed
64 65 66 67 68 69
  final Widget title;

  /// The color of the background radial animation for material [BottomNavigationBar].
  ///
  /// If the navigation bar's type is [BottomNavigationBarType.shifting], then
  /// the entire bar is flooded with the [backgroundColor] when this item is
70
  /// tapped. This will override [BottomNavigationBar.backgroundColor].
xster's avatar
xster committed
71 72 73 74 75 76 77 78 79 80
  ///
  /// Not used for [CupertinoTabBar]. Control the invariant bar color directly
  /// via [CupertinoTabBar.backgroundColor].
  ///
  /// See also:
  ///
  ///  * [Icon.color] and [ImageIcon.color] to control the foreground color of
  ///     the icons themselves.
  final Color backgroundColor;
}