Repository: flutter
Issue: Focus traversal broken with empty AppBar and nested navigators
Labels: framework,f: material design,f: routes,f: focus,has reproducible steps,P2,team-design,triaged-design,found in release: 3.22,found in release: 3.23

### Steps to reproduce

Run the attached minimal sample on Chrome (web). I haven't tested it on Mobile platforms yet.

### Expected results

Focus traversal works properly for both panes

### Actual results

Focus traversal is broken, but just replace the `ChildPageView`'s `AppBar` with the following and it suddendly works.

```
AppBar(
        title: const Text('Home page'),
        actions: [
          IconButton(
            icon: const Icon(Icons.help_center_rounded),
            onPressed: () => {},
          ),
          IconButton(
            icon: const Icon(Icons.help_center_rounded),
            onPressed: () => {},
          ),
          IconButton(
            icon: const Icon(Icons.help_center_rounded),
            onPressed: () => {},
          )
        ],
      )
```



### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Responsive Navigation App',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      initialRoute: '/',
      onGenerateRoute: (settings) {
        if (settings.name == '/') {
          return MaterialPageRoute(
            builder: (_) => const HomePageView(),
          );
        } else {
          return MaterialPageRoute(
            builder: (_) => const Scaffold(
              body: Center(
                child: Text('Route not found'),
              ),
            ),
          );
        }
      },
    );
  }
}

class HomePageView extends StatefulWidget {
  const HomePageView({super.key});

  @override
  State<HomePageView> createState() => _HomePageViewState();
}

class _HomePageViewState extends State<HomePageView> {
  @override
  Widget build(BuildContext context) {
    return Container(
      constraints: const BoxConstraints.expand(),
      child: Row(
        children: [
          Flexible(
            child: Row(
              children: [
                NavigationRail(
                  selectedIndex: 0,
                  destinations: const <NavigationRailDestination>[
                    NavigationRailDestination(
                      icon: Icon(Icons.favorite_border),
                      selectedIcon: Icon(Icons.favorite),
                      label: Text('First'),
                    ),
                    NavigationRailDestination(
                      icon: Icon(Icons.bookmark_border),
                      selectedIcon: Icon(Icons.book),
                      label: Text('Second'),
                    ),
                    NavigationRailDestination(
                      icon: Icon(Icons.star_border),
                      selectedIcon: Icon(Icons.star),
                      label: Text('Third'),
                    ),
                  ],
                ),
                Expanded(
                  child: ScaffoldMessenger(
                    child: Scaffold(
                      appBar: AppBar(
                        title: const Text('Home page'),
                        actions: [
                          IconButton(
                            icon: const Icon(Icons.help_center_rounded),
                            onPressed: () => {},
                          ),
                          IconButton(
                            icon: const Icon(Icons.help_center_rounded),
                            onPressed: () => {},
                          ),
                          IconButton(
                            icon: const Icon(Icons.help_center_rounded),
                            onPressed: () => {},
                          )
                        ],
                      ),
                    ),
                  ),
                ),
                Flexible(
                  child: Navigator(
                    initialRoute: '/',
                    onGenerateRoute: (settings) {
                      if (settings.name == '/') {
                        return MaterialPageRoute(
                          builder: (_) => const ChildPageView(),
                        );
                      } else {
                        return MaterialPageRoute(
                          builder: (_) => const Scaffold(
                            body: Center(
                              child: Text('Route not found'),
                            ),
                          ),
                        );
                      }
                    },
                  ),
                )
              ],
            ),
          ),
        ],
      ),
    );
  }
}

class ChildPageView extends StatefulWidget {
  const ChildPageView({super.key});

  @override
  State<ChildPageView> createState() => _ChildPageViewState();
}

class _ChildPageViewState extends State<ChildPageView> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
    );
  }
}

```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[√] Flutter (Channel stable, 3.22.2, on Microsoft Windows [Versione 10.0.19045.4529], locale it-IT)
    • Flutter version 3.22.2 on channel stable at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 761747bfc5 (4 weeks ago), 2024-06-05 22:15:13 +0200
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\Alessandro\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0--11609105)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[!] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.4)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.8.34408.163
    X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components:
        MSVC v142 - VS 2019 C++ x64/x86 build tools
         - If there are multiple build tool versions available, install the latest
        C++ CMake tools for Windows
        Windows 10 SDK

[√] Android Studio (version 2024.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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
    • android-studio-dir = C:\Program Files\Android\Android Studio
    • Java version OpenJDK Runtime Environment (build 17.0.10+0--11609105)

[√] VS Code (version 1.71.2)
    • VS Code at C:\Users\Alessandro\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.48.0

[√] Connected device (4 available)
    • Pixel Fold (mobile) • 35181FDHS00206 • android-arm64  • Android 14 (API 34)
    • Windows (desktop)   • windows        • windows-x64    • Microsoft Windows [Versione 10.0.19045.4529]
    • Chrome (web)        • chrome         • web-javascript • Google Chrome 126.0.6478.114
    • Edge (web)          • edge           • web-javascript • Microsoft Edge 126.0.2592.81

[√] Network resources
    • All expected network resources are available.

```

</details>