Skip to content
Blog

Responsive Ergonomics: NavigationRail for Desktop and Tablet Flutter Apps

Master NavigationRail in Flutter to build responsive side navigation bars optimized for tablet, desktop, and foldable form factors.

Published on • November 9, 2026

AI Assistant

When adapting a Flutter app from mobile screens to tablets, foldables, and desktop monitors, a bottom navigation bar consumes unnecessary vertical height while leaving wide horizontal margins underutilized.

The NavigationRail widget provides a side navigation bar pattern optimized for wide displays, keeping primary actions accessible along the left edge of the screen.

Basic NavigationRail Structure

NavigationRail mirrors the API of BottomNavigationBar. It uses NavigationRailDestination items, tracks a selectedIndex, and triggers onDestinationSelected callbacks.

import 'package:flutter/material.dart';

class ResponsiveShell extends StatefulWidget {
  const ResponsiveShell({super.key});

  @override
  State<ResponsiveShell> createState() => _ResponsiveShellState();
}

class _ResponsiveShellState extends State<ResponsiveShell> {
  int _selectedIndex = 0;
  bool _isExtended = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Row(
        children: [
          NavigationRail(
            selectedIndex: _selectedIndex,
            extended: _isExtended,
            onDestinationSelected: (index) {
              setState(() => _selectedIndex = index);
            },
            leading: IconButton(
              icon: Icon(_isExtended ? Icons.menu_open : Icons.menu),
              onPressed: () {
                setState(() => _isExtended = !_isExtended);
              },
            ),
            trailing: Expanded(
              child: Align(
                alignment: Alignment.bottomCenter,
                child: Padding(
                  padding: const EdgeInsets.only(bottom: 16.0),
                  child: IconButton(
                    icon: const Icon(Icons.settings),
                    onPressed: () {},
                  ),
                ),
              ),
            ),
            destinations: const [
              NavigationRailDestination(
                icon: Icon(Icons.dashboard_outlined),
                selectedIcon: Icon(Icons.dashboard),
                label: Text('Dashboard'),
              ),
              NavigationRailDestination(
                icon: Icon(Icons.analytics_outlined),
                selectedIcon: Icon(Icons.analytics),
                label: Text('Analytics'),
              ),
              NavigationRailDestination(
                icon: Icon(Icons.people_outline),
                selectedIcon: Icon(Icons.people),
                label: Text('Customers'),
              ),
            ],
          ),
          const VerticalDivider(thickness: 1, width: 1),
          Expanded(
            child: IndexedStack(
              index: _selectedIndex,
              children: const [
                Center(child: Text('Dashboard Content')),
                Center(child: Text('Analytics Content')),
                Center(child: Text('Customers Content')),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

Creating an Adaptive Layout Switcher

Using LayoutBuilder or MediaQuery, you can seamlessly switch between a bottom NavigationBar on mobile screens and a left-side NavigationRail on desktop or tablet viewports.

class AdaptiveNavigationShell extends StatefulWidget {
  const AdaptiveNavigationShell({super.key});

  @override
  State<AdaptiveNavigationShell> createState() => _AdaptiveNavigationShellState();
}

class _AdaptiveNavigationShellState extends State<AdaptiveNavigationShell> {
  int _selectedIndex = 0;

  @override
  Widget build(BuildContext context) {
    final width = MediaQuery.of(context).size.width;
    final isDesktop = width >= 800;

    return Scaffold(
      body: Row(
        children: [
          if (isDesktop)
            NavigationRail(
              selectedIndex: _selectedIndex,
              extended: width >= 1100,
              onDestinationSelected: (idx) => setState(() => _selectedIndex = idx),
              destinations: _buildRailDestinations(),
            ),
          if (isDesktop) const VerticalDivider(thickness: 1, width: 1),
          Expanded(
            child: Center(child: Text('Screen Index: $_selectedIndex')),
          ),
        ],
      ),
      bottomNavigationBar: !isDesktop
          ? NavigationBar(
              selectedIndex: _selectedIndex,
              onDestinationSelected: (idx) => setState(() => _selectedIndex = idx),
              destinations: _buildBarDestinations(),
            )
          : null,
    );
  }

  List<NavigationRailDestination> _buildRailDestinations() {
    return const [
      NavigationRailDestination(icon: Icon(Icons.home), label: Text('Home')),
      NavigationRailDestination(icon: Icon(Icons.settings), label: Text('Settings')),
    ];
  }

  List<NavigationDestination> _buildBarDestinations() {
    return const [
      NavigationDestination(icon: Icon(Icons.home), label: 'Home'),
      NavigationDestination(icon: Icon(Icons.settings), label: 'Settings'),
    ];
  }
}

Customizing NavigationRail Appearance

  • labelType: Controls label visibility (NavigationRailLabelType.none, all, or selected). When extended: true is set, labelType must be none.
  • elevation: Adds a shadow elevation to visually lift the rail above the main content area.
  • minWidth & minExtendedWidth: Sets explicit pixel dimensions for collapsed and expanded states.

Takeaway: Combining NavigationRail with responsive breakpoints transforms mobile Flutter apps into spacious, ergonomic multi-column desktop applications.