addItem method

  1. @override
BottomToNavRailImpl addItem({
  1. required String label,
  2. required IconData icon,
  3. IconData? selectedIcon,
})
override

Typically, the size and other properties of the navigation item need to be customized. Therefore, we use an Icon instead of IconData to reduce the need for additional wrapping in the consumer code.

Furthermore, the color of the navigation items should be consistent across all items, using either the primary or secondary color,because it is clickable. To achieve this, you can pass the color through different parameters or edit the code here.

Since this code is used in different projects, and an app usually has only one navigation decorator, it is acceptable to edit the source code per project to avoid unnecessary methods and lengthy code.

Implementation

@override
BottomToNavRailImpl addItem({
  required String label,
  required IconData icon,
  IconData? selectedIcon,
}) {
  _navigationItems.add(NavigationItem(
    label: label,
    icon: Icon(icon),
    selectedIcon: Icon(selectedIcon),
  ));
  return this;
}