build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Implementation

@override
Widget build(BuildContext context) {
  if (_navigationItems.isEmpty || _body == null || _selectedIndex == null) {
    throw Exception(
        "Navigation items, body, and selected index must be provided.");
  }

  final double screenWidth = MediaQuery.of(context).size.width;
  final bool useBottomNavigationBar = screenWidth < 600;

  return Scaffold(
    appBar: _appBar,
    body: Row(
      children: [
        if (!useBottomNavigationBar)
          NavigationRail(
            selectedIndex: _selectedIndex!,
            onDestinationSelected: _onItemClicked,
            labelType: NavigationRailLabelType.selected,
            destinations: _navigationItems.map((item) {
              return NavigationRailDestination(
                icon:Icon( item.icon.icon,color: _iconColor!=null?_iconColor:Theme.of(context).primaryColor),
                selectedIcon: item.selectedIcon ?? item.icon,
                label: Text(item.label),
              );
            }).toList(),
          ),
        Expanded(
          child: _body!,
        ),
      ],
    ),
    bottomNavigationBar: useBottomNavigationBar
        ? NavigationBar(
            selectedIndex: _selectedIndex!,
            onDestinationSelected: _onItemClicked,
            indicatorColor: Colors.amber,
            destinations: _navigationItems.map((item) {
              return NavigationDestination(
                icon: item.icon,
                selectedIcon: item.selectedIcon ?? item.icon,
                label: item.label,
              );
            }).toList(),
          )
        : null,
    floatingActionButton: _fab,
  );
}