standardBottomNavigationBar static method

Builder standardBottomNavigationBar({
  1. required List<NavigationDestination> destinations,
  2. int? currentIndex,
  3. double iconSize = 24,
  4. Color? backgroundColor,
  5. ValueChanged<int>? onDestinationSelected,
})

Public helper method to be used for creating a BottomNavigationBar from a list of NavigationDestinations.

Implementation

static Builder standardBottomNavigationBar({
  required List<NavigationDestination> destinations,
  int? currentIndex,
  double iconSize = 24,
  Color? backgroundColor,
  ValueChanged<int>? onDestinationSelected,
}) {
  return Builder(
    builder: (BuildContext context) {
      final NavigationBarThemeData currentNavBarTheme =
          NavigationBarTheme.of(context);
      return NavigationBarTheme(
        data: currentNavBarTheme.copyWith(
          iconTheme: WidgetStateProperty.resolveWith(
            (Set<WidgetState> states) {
              return currentNavBarTheme.iconTheme
                      ?.resolve(states)
                      ?.copyWith(size: iconSize) ??
                  IconTheme.of(context).copyWith(size: iconSize);
            },
          ),
        ),
        child: MediaQuery(
          data: MediaQuery.of(context).removePadding(removeTop: true),
          child: NavigationBar(
            backgroundColor: backgroundColor ?? Theme.of(context).colorScheme.surface,
            selectedIndex: currentIndex ?? 0,
            destinations: destinations,
            onDestinationSelected: onDestinationSelected,
          ),
        ),
      );
    },
  );
}