Navigation drawer
A navigation drawer or sidebar gives destinations room for a full label. A persistent sidebar is useful when a wide layout has space beside the current page.
Choose from a sidebar
#Choose Home or Search from the open panel. The current page is printed below it.
components/navigation-drawer/appliance/switch_destination.dart
import 'package:flutter/widgets.dart';
import 'package:material_ui/material_ui.dart' show Icons;
import 'package:appliance_ui/appliance_ui.dart';
class SwitchDestination extends StatefulWidget {
const SwitchDestination({super.key});
@override
State<SwitchDestination> createState() => _SwitchDestinationState();
}
class _SwitchDestinationState extends State<SwitchDestination> {
int selected = 0;
static const destinations = [
ApplianceDestination(icon: Icons.home_outlined, label: 'Home'),
ApplianceDestination(icon: Icons.search, label: 'Search'),
];
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 680),
child: Column(
children: [
Expanded(
child: Align(
alignment: AlignmentDirectional.centerStart,
child: ApplianceSideNavigation(
destinations: destinations,
selectedIndex: selected,
onSelected: (next) => setState(() => selected = next),
),
),
),
const SizedBox(height: 8),
Text(selected == 0 ? 'Home page' : 'Search page'),
],
),
);
}
Parameters
ApplianceSideNavigation API ↗destinations- The destinations in reading order.
selectedIndex- Zero-based index of the visible page.
onSelected- Receives the index of the chosen destination.
Shared behaviour
- Keyboard and focus. Tab into the panel and follow the focus indicator to a destination. Activate it to change the page.
- Screen readers. Read the destination names and inspect which is selected. Continue past the panel for the current page.
- Direction and type. Switch to RTL to move the panel to the reading start. At larger type, inspect each destination’s label in the open panel.