Overview
HuxSidebar is a complete navigation component that provides a consistent sidebar layout with header, navigation items, and optional footer. It handles selection state management automatically and provides a clean API for sidebar navigation in your Flutter applications.Basic Usage
Simple Sidebar
Basic sidebar with navigation items:Sidebar with Header
Sidebar with custom header content:Sidebar with Footer
Include footer content like user profile or settings:Navigation Items
HuxSidebarItemData
Define individual navigation items:Multiple Items
Create a list of navigation items:Properties
HuxSidebar Properties
Property | Type | Default | Description |
---|---|---|---|
items | List<HuxSidebarItemData> | required | List of navigation items |
onItemSelected | Function(String) | required | Callback when item is selected |
selectedItemId | String? | null | Currently selected item ID |
header | Widget? | null | Optional header widget |
footer | Widget? | null | Optional footer widget |
width | double | 250 | Width of the sidebar |
padding | EdgeInsets | vertical: 16 | Padding around items |
HuxSidebarItemData Properties
Property | Type | Default | Description |
---|---|---|---|
id | String | required | Unique identifier for the item |
label | String | required | Display label for the item |
icon | IconData? | null | Optional leading icon |
Styling
Custom Width
Adjust sidebar width for your layout:Custom Padding
Control spacing around navigation items:States
Selection State
Items automatically show selected state based onselectedItemId
:
- Selected: Highlighted with primary color background
- Unselected: Default appearance with hover state
- Hovered: Subtle background change on mouse hover
Integration Examples
With Routing
Integrate with your app’s routing system:With Responsive Layout
Make sidebar responsive to screen size:Best Practices
Navigation Structure
Navigation Structure
Selection Management
Selection Management
- Always maintain a selected state
- Update selected item when route changes
- Provide visual feedback for current location
- Consider highlighting active section in multi-level navigation
Responsive Design
Responsive Design
- Hide sidebar on small screens and use drawer instead
- Adjust sidebar width based on screen size
- Consider collapsible sidebar for medium screens
- Ensure touch targets are at least 44x44 pixels
Accessibility
Accessibility
- Ensure keyboard navigation works smoothly
- Provide clear focus indicators
- Use semantic labels for screen readers
- Maintain sufficient color contrast (WCAG AA)
Theme Integration
HuxSidebar automatically adapts to your app’s theme:- Light Mode: Clean white background with subtle borders
- Dark Mode: Dark background with appropriate contrast
- Selected State: Uses theme primary color
- Hover State: Subtle background change based on theme
Related Components
- HuxButton - Action buttons within sidebar
- HuxAvatar - User avatars in sidebar footer
- HuxBadge - Notification badges on items
- HuxTooltip - Tooltips for collapsed sidebar