Skip to content

[flutter_adaptive_scaffold] Leading and Trailing widgets are not visible on NavigationRail #114684

@sabin26

Description

@sabin26

Steps to Reproduce

  1. Execute flutter run on the code sample
  2. Resize window

Expected results:
On Extended Navigation Rail:
nav_rail_extended

On Unextended Navigation Rail: (Since there is no trailingUnextendedNavRail property)
nav_rail_unextended

Actual results:
On Extended Navigation Rail:
nav_rail_extended_issue

On Unextended Navigation Rail:
nav_rail_unextended_issue

Code sample
import 'package:flutter/material.dart';
import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorSchemeSeed: const Color(0xFFE4935D),
        useMaterial3: true,
        brightness: Brightness.light,
      ),
      // darkTheme: ThemeData(
      //   colorSchemeSeed: const Color(0xFFE4935D),
      //   useMaterial3: true,
      //   brightness: Brightness.dark,
      // ),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return AdaptiveScaffold(
      appBar: AppBar(
        elevation: 4,
        title: const Text('Demo App'),
      ),
      useDrawer: false,
      trailingNavRail: OutlinedButton.icon(
        icon: const Icon(Icons.exit_to_app),
        onPressed: () {},
        label: const Text('Exit'),
      ),
      leadingExtendedNavRail: OutlinedButton.icon(
        icon: const Icon(Icons.add),
        onPressed: () {},
        label: const Text('New'),
      ),
      leadingUnextendedNavRail: IconButton(
        icon: const Icon(Icons.add),
        onPressed: () {},
      ),
      destinations: const <NavigationDestination>[
        NavigationDestination(
          icon: Icon(Icons.home),
          label: 'Home',
        ),
        NavigationDestination(
          icon: Icon(Icons.add_box),
          label: 'Counter',
        ),
      ],
      body: (final _) {
        return const SizedBox.shrink();
      },
      onSelectedIndexChange: (final index) {},
    );
  }
}

This issue is caused because the leading and trailing widgets are not passed into AdaptiveScaffold.standardNavigationRail() function from AdaptiveScaffold widget in adaptive_scaffold.dart.

The solution:

After providing leading and trailing widgets to AdaptiveScaffold.standardNavigationRail() from AdaptiveScaffold widget, it works as expected.

class _AdaptiveScaffoldState extends State<AdaptiveScaffold> {
  @override
  Widget build(BuildContext context) {
    return Directionality(
      ...
        body: AdaptiveLayout(
          bodyOrientation: widget.bodyOrientation,
          bodyRatio: widget.bodyRatio,
          internalAnimations: widget.internalAnimations,
          primaryNavigation: SlotLayout(
            config: <Breakpoint, SlotLayoutConfig>{
              widget.mediumBreakpoint: SlotLayout.from(
                key: const Key('primaryNavigation'),
                builder: (_) => AdaptiveScaffold.standardNavigationRail(
                  width: widget.navigationRailWidth,
                  selectedIndex: widget.selectedIndex,
                  leading: widget.leadingUnextendedNavRail, // add this line
                  destinations: widget.destinations
                      .map((_) => AdaptiveScaffold.toRailDestination(_))
                      .toList(),
                  onDestinationSelected: widget.onSelectedIndexChange,
                ),
              ),
              widget.largeBreakpoint: SlotLayout.from(
                key: const Key('primaryNavigation1'),
                builder: (_) => AdaptiveScaffold.standardNavigationRail(
                  width: widget.extendedNavigationRailWidth,
                  extended: true,
                  leading: widget.leadingExtendedNavRail, // add this line
                  trailing: widget.trailingNavRail, // add this line
                  selectedIndex: widget.selectedIndex,
                  destinations: widget.destinations
                      .map((_) => AdaptiveScaffold.toRailDestination(_))
                      .toList(),
                  onDestinationSelected: widget.onSelectedIndexChange,
                ),
              ),
            },
          ),
          ...
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 3.3Found to occur in 3.3found in release: 3.5Found to occur in 3.5has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: flutter_adaptive_scaffoldThe flutter_adaptive_scaffold packagepackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions