Repository: flutter
Issue: Nested Navigator and focusing problem (not a GoRouter)
Labels: framework,f: routes,f: focus,has reproducible steps,P2,team-framework,triaged-framework,found in release: 3.27,found in release: 3.28

### Steps to reproduce

1. Launch flutter debugging app for Linux/AVD Android TV (flutter run).
2. If top widget says "Up (nested Navigator)" try to use arrow keys (Up/Down) to focus something.

### Expected results

Top, top nested containers and bottom widgets can receive focus using Arrow keys.

### Actual results

Top receives focus and holds it due to which it is impossible to focus on the bottom.

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const App());
}

class App extends StatelessWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    bool seeProblem = true;
    return MaterialApp(
      theme: ThemeData.from(colorScheme: ColorScheme.dark()),
      home: StatefulBuilder(
        builder: (context, setState) {
          return Scaffold(
            body: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Expanded(
                  child: TheProblem(seeProblem: seeProblem),
                ),
                Row(
                  children: [
                    Text('Toggle to problem view: '),
                    Switch(value: seeProblem, onChanged: (a) {
                      setState(() {
                        seeProblem = a;
                      });
                    }),
                  ],
                ),
                Padding(
                  padding:  EdgeInsets.all(20.0),
                  child: Text(
                    'Use switch to toggle between problematic and good views.\n'
                    'When on "Up (in Navigator)" try to use Arrow navigation.\n'
                    'When on "Up (no nested Navigator)" try to use Arrow navigation.\n'
                    'While second one produces right focusing using Arrows and Tabs,\n'
                    'the first example has problem with using Arrows\n'
                  ),
                )
              ],
            ),
          );
        },
      ),
    );
  }
}

class TheProblem extends StatelessWidget {
  const TheProblem({
    super.key,
    required this.seeProblem,
  });

  final bool seeProblem;

  @override
  Widget build(BuildContext context) {
    if (seeProblem) {
      return Scaffold(
        body: Navigator(
          onGenerateRoute: (settings) {
            return MaterialPageRoute(
                builder: (context) {
                  return Center(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        FocusableContainer(name: "Up (in Navigator)"),
                        Row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            FocusableContainer(name: "1"),
                            FocusableContainer(name: "2"),
                            FocusableContainer(name: "3"),
                          ],
                        )
                      ],
                    )
                  );
                }
            );
          },
        ),
        bottomNavigationBar: ConstrainedBox(
          constraints: BoxConstraints(
              maxHeight: 100
          ),
          child: FocusableContainer(name: "Down"),
        ),
      );
    }
    return Scaffold(
      body: SizedBox.expand(
        child: FocusableContainer(name: "Up (no nested Navigator)"),
      ),
      bottomNavigationBar: ConstrainedBox(
        constraints: BoxConstraints(
          maxHeight: 100
        ),
        child: FocusableContainer(name: "Down"),
      ),
    );
  }
}

class FocusableContainer extends StatefulWidget {
  const FocusableContainer({
    super.key,
    required this.name,
  });

  final String name;

  @override
  State<FocusableContainer> createState() => _FocusableContainerState();
}

class _FocusableContainerState extends State<FocusableContainer> {
  bool focused = false;

  @override
  Widget build(BuildContext context) {
    return Focus(
      onFocusChange: (focused) {
        setState(() {
          this.focused = focused;
        });
      },
      child: Container(
        decoration: BoxDecoration(
          border: Border.all(
            color: focused ? Colors.green : Colors.transparent,
          )
        ),
        padding: EdgeInsets.all(20.0),
        child: Center(
          child: Text(widget.name),
        ),
      ),
    );
  }
}

```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration of focusing using Arrows, then Tab keys</summary>

[Screencast from 2024-12-25 14-10-38.webm](https://github.com/user-attachments/assets/35ddbd74-7515-4dc0-94a0-9fa074ffaca3)


</details>


### Logs

_No response_

### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.27.0, on Ubuntu 24.04.1 LTS 6.8.0-51-generic,
    locale en_US.UTF-8)
    • Flutter version 3.27.0 on channel stable at /home/i8s/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 8495dee1fd (2 weeks ago), 2024-12-10 14:23:39 -0800
    • Engine revision 83bacfc525
    • Dart version 3.6.0
    • DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /home/i8s/Android/Sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: /mnt/Apps/development/jdk-20/bin/java
    • Java version OpenJDK Runtime Environment (build 20+36-2344)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at
    google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Linux toolchain - develop for Linux desktop
    • Ubuntu clang version 18.1.3 (1ubuntu1)
    • cmake version 3.28.3
    • ninja version 1.11.1
    • pkg-config version 1.8.1

[✓] Android Studio (version 2024.2)
    • Android Studio at /home/i8s/development/android-studio
    • Flutter plugin version 83.0.3
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)

[✓] VS Code (version 1.96.2)
    • VS Code at /snap/code/current/usr/share/code
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (1 available)
    • Linux (desktop) • linux • linux-x64 • Ubuntu 24.04.1 LTS 6.8.0-51-generic

[✓] Network resources
    • All expected network resources are available.
```

</details>