Navigation rail
A navigation rail keeps a short list of destinations along the leading edge of a view, leaving room for the current page.
Navigate along a rail
#Choose Search on the rail to change the content beside it. Return to Home to restore the first page.
components/navigation-rail/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: 740),
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ApplianceNavigationRail(
destinations: destinations,
selectedIndex: selected,
onSelected: (next) => setState(() => selected = next),
),
Expanded(
child: Center(
child: Text(selected == 0 ? 'Home page' : 'Search page'),
),
),
],
),
);
}
Parameters
ApplianceNavigationRail 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. Focus the destinations and move down the rail. Activate Search if moving focus alone leaves Home selected.
- Screen readers. Inspect the destination names and selected state, then read the content next to the rail.
- Direction and type. The rail sits at the reading start. Switch to RTL to move it to the other side of the content and try larger text at phone width.