Repository: flutter
Issue: ListView wrapped with a FocusTraversalGroup and placed between two text buttons, the focus does not follow correct order using up and down arrow keys.
Labels: framework,a: desktop,f: focus,has reproducible steps,P3,team-framework,triaged-framework,found in release: 3.24,found in release: 3.27

### Steps to reproduce

When a ListView is wrapped with a FocusTraversalGroup and placed between two text buttons, the focus behaves erratically when using the arrow up and down keys. See the attached video made with the attached code. This makes it very hard to get the focus behavior that we want in more complicated scenarios.

Please run attached main.dart on Android or iOS device.

1. Use the Arrow Down key to get to the last element on the page. 
2. Use the Arrow Up key.
3. Use the Arrow Down key to get to the second element in the list.
4.  Use the Arrow Up key two times.
5. Use the Arrow Up key to get to the topmost button.
6. Use the Arrow Down key once to get to the first item in the list.
7. Use the Arrow Down key once.

### Expected results

1. Focus is on the last element on the page.
2. Focus is moved to the last element in the list.
3. .
4. Focus is moved to topmost element on the page.
5.  .
6. .
7. Focus is moved to the second element in the list.


### Actual results

1. Focus is on the last element on the page.
2. Focus is moved to the topmost element on the page.
3.  .
4. Focus is moved to the last element in the list.
5.  .
6.  .
7. Focus remains on the first element in the list.

### 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});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(title: 'Focus Bug', home: Scaffold(body: MyHomePage()));
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return ListView(
      physics: const AlwaysScrollableScrollPhysics(),
      children: [
        TextButton(onPressed: () {}, child: const Text('Button')),
        FocusTraversalGroup(
          child: ListView.separated(
            shrinkWrap: true,
            physics: const NeverScrollableScrollPhysics(),
            itemBuilder: (context, index) {
              return TextButton(
                onPressed: () {},
                child: const Text('ListTextButton'),
              );
            },
            separatorBuilder: (context, index) => const SizedBox(height: 8),
            itemCount: 5,
          ),
        ),
        TextButton(onPressed: () {}, child: const Text('Button')),
      ],
    );
  }
}

```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>


https://github.com/user-attachments/assets/d0bf13fe-aeaa-41ca-aec8-ce5ebbcb14b1



</details>


### Logs

<details open><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
$ flutter doctor -v
[√] Flutter (Channel master, 3.27.0-1.0.pre.645, on Microsoft Windows [Version 10.0.19045.5131], locale en-SE)
    • Flutter version 3.27.0-1.0.pre.645 on channel master at C:\Users\henrik.andersson\fvm\versions\3.19.6
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 1e824af6bd (12 hours ago), 2024-11-25 21:55:41 -0500
    • Engine revision fb64399182
    • Dart version 3.7.0 (build 3.7.0-184.0.dev)
    • DevTools version 2.41.0-dev.2

[√] Windows Version (10 Enterprise 64-bit, 22H2, 2009)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\henrik.andersson\AppData\Local\Android\sdk
    • Platform android-35, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio3\jbr\bin\java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop Windows apps
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2023.2)
    • Android Studio at C:\Program Files\Android\Android Studio1
    • 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
    • Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874)

[√] Android Studio (version 2024.1)
    • Android Studio at C:\Program Files\Android\Android Studio2
    • 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
    • Java version OpenJDK Runtime Environment (build 17.0.10+0--11609105)

[√] Android Studio (version 2024.2)
    • Android Studio at C:\Program Files\Android\Android Studio3
    • 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
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)

[√] VS Code (version 1.94.2)
    • VS Code at C:\Users\henrik.andersson\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.88.0

[√] Connected device (4 available)
    • SM G973F (mobile) • RF8M91E2RSB • android-arm64  • Android 10 (API 29)
    • Windows (desktop) • windows     • windows-x64    • Microsoft Windows [Version 10.0.19045.5131]
    • Chrome (web)      • chrome      • web-javascript • Google Chrome 130.0.6723.117
    • Edge (web)        • edge        • web-javascript • Microsoft Edge 131.0.2903.63

[√] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

```

</details>