bottom_nav_bar

Function bottom_nav_bar 

Source
pub fn bottom_nav_bar<F>(state: Arc<RwLock<BottomNavBarState>>, scope_config: F)
where F: FnOnce(&mut BottomNavBarScope<'_>),
Expand description

A horizontal bottom navigation bar that hosts multiple navigation items (children), each with its own click callback. The currently selected item is visually highlighted (pill style) and tracked inside a shared BottomNavBarState.

§State Handling

  • The state: Arc<RwLock<BottomNavBarState>> holds:
    • selected: index of the active item
    • A lazily created RippleState per item (for button ripple feedback)
  • The active item is rendered with a capsule shape & filled color; inactive items are rendered as transparent buttons.

§Building Children

Children are registered via the provided closure scope_config which receives a mutable BottomNavBarScope. Each child is added with: scope.child(content_closure, on_click_closure).

on_click_closure is responsible for performing side effects (e.g. pushing a new route). The component automatically updates selected and triggers the ripple state before invoking the user on_click.

§Layout

Internally the bar is:

  • A full‑width surface (non‑interactive container)
  • A row whose children are spaced using MainAxisAlignment::SpaceAround

§Notes

  • Indices are assigned in the order children are added.
  • The bar itself does not do routing — supply routing logic inside each child’s on_click closure.
  • Thread safety for selected & ripple states is provided by RwLock.