Skip to content

Navigation in ToolbarOverflowMenuItem not working #346

@bkuensting

Description

@bkuensting

Description
Navigation by ToolBarIconButton works, but if the button is automatically moved to the overflow menu due to missing space, navigation doesn't work anymore. That is, Navigator.of(context).push(...) seems to have no effect anymore.

Steps To Reproduce

  1. Use the provided code
  2. Enlarge the main window so that the Add icon (circled plus) in the toolbar is visible
  3. Click on the Add icon
  4. In the sub view click the chevron in front of "Sub View" to go back
  5. Now shrink the window width so that the Add icon is moved to the overflow menu
  6. Click the double chevron on the right side of the toolbar to open the overflow menu
  7. Click on "Add..."
  8. Nothing happens, no navigation
Code sample
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:macos_ui/macos_ui.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const DeviceAccessManagerApp());
}

class DeviceAccessManagerApp extends StatelessWidget {
  const DeviceAccessManagerApp({Key? key}) : super(key: key);

// This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MacosApp(
      title: 'Navigation bug',
      theme: MacosThemeData.light(),
      darkTheme: MacosThemeData.dark(),
      themeMode: ThemeMode.system,
      debugShowCheckedModeBanner: false,
      home: MainView(),
    );
  }
}

class MainView extends StatelessWidget {
  MainView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MacosWindow(
      sidebar: Sidebar(
        minWidth: 200,
        builder: (context, scrollController) {
          return SidebarItems(
            currentIndex: 0,
            onChanged: (index) {
              print("sidebar onChanged");
            },
            items: const [
              SidebarItem(
                leading: MacosIcon(CupertinoIcons.home),
                label: Text('Home'),
              ),
            ],
          );
        },
      ),
      child: IndexedStack(
        index: 0,
        children: const [
          HomeView(),
        ],
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return CupertinoTabView(
      builder: (context) => MacosScaffold(
        toolBar: ToolBar(
          title: const Text("Home"),
          automaticallyImplyLeading: true,
          actions: [
            CustomToolbarItem(
              inToolbarBuilder: (context) => const SizedBox(
                  width: 400,
                  child: MacosSearchField(
                    placeholder: "Search for something",
                    maxLines: 1,
                  )),
            ),
            const ToolBarSpacer(),
            ToolBarIconButton(
              label: "Add...",
              icon: const MacosIcon(
                CupertinoIcons.add_circled,
              ),
              onPressed: () {
                print("Add... onPressed");
                Navigator.of(context).push(CupertinoPageRoute(builder: (context) => const SubView()));
              },
              showLabel: false,
            ),
          ],
        ),
        children: <Widget>[
          ContentArea(builder: (context) {
            return const Center(child: Text("Hello from Home View"));
          }),
        ],
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return MacosScaffold(
      toolBar: const ToolBar(
        title: Text("Sub View"),
      ),
      children: <Widget>[
        ContentArea(builder: (context) {
          return const Center(child: Text("Hello from Sub View"));
        }),
      ],
    );
  }
}

Expected behavior
Even when toolbar icons are moved to the overflow menu, I would expect that navigation via Navigator.of(context).push(...) still works

Screenshots
2023-02-07 13 49 14

Logs

Logs
Log too long
Analyzing bug...
No issues found! (ran in 0.7s)
[✓] Flutter (Channel stable, 3.7.1, on macOS 13.2 22D49 darwin-arm64, locale en-DE)
    • Flutter version 3.7.1 on channel stable at /Users/bjoern/.asdf/installs/flutter/3.7.1-stable
    • Upstream repository ssh://git@github.com/flutter/flutter.git
    • FLUTTER_GIT_URL = ssh://git@github.com/flutter/flutter.git
    • Framework revision 7048ed95a5 (6 days ago), 2023-02-01 09:07:31 -0800
    • Engine revision 800594f1f4
    • Dart version 2.19.1
    • DevTools version 2.20.1

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed
      instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed
      instructions).

[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.2)
    • IntelliJ at /Users/bjoern/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 71.3.6
    • Dart plugin version 223.8617.8

[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.2)
    • IntelliJ at /Users/bjoern/Library/Application
      Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/223.8617.56/IntelliJ IDEA.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.1)
    • IntelliJ at /Users/bjoern/Library/Application
      Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/223.8214.52/IntelliJ IDEA.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.75.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.2 22D49 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 109.0.5414.119

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 2 categories.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions