Repository: flutter
Issue: [Web]: Strange Hit Testing when Flutter Semantics enabled.
Labels: framework,f: gestures,platform-web,has reproducible steps,P2,team-framework,triaged-framework,found in release: 3.19,found in release: 3.20

### Steps to reproduce

1. Click Enable Semantics.
2. Over over the dropdown and click Option 1.

### Expected results

You should see "Option 1 pressed!" in the console.

### Actual results

You see "Submit Button pressed!" in the console, indicating that the submit button underneath the "Option 1" menu item was clicked instead of Option 1 itself.

### Code sample

<details open><summary>Code sample</summary>

```dart
// This dart file reproduces a bug with Flutter Semantics. In certain
// situations, clicking a dropdown menu item with semantics enabled will hit
// the element under it.

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: GoogleMaterial.theme(colors: GoogleColorScheme.light),
      darkTheme: GoogleMaterial.theme(colors: GoogleColorScheme.dark),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String dropdownValue = 'Option 1';
  SemanticsHandle? _semanticsHandle;

  final _options = ['Option 1', 'Option 2', 'Option 3', 'Option 4'];

  @override
  Widget build(BuildContext context) {
    final row = Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Expanded(
            child: ClipRect(
          child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(
                  // First option covers the button underneath it.
                  // When clicked, users should see "Option x pressed" in the
                  // Chrome console.
                  child: Semantics(
                      container: true,
                      child: SubmenuButton(
                        menuChildren: _options
                            .map((option) => MenuItemButton(
                                  onPressed: () {
                                    print('$option pressed');
                                  },
                                  child: Text(option),
                                ))
                            .toList(),
                        child: MenuAcceleratorLabel('Dropdown'),
                      )),
                ),
                Padding(
                  padding: EdgeInsetsDirectional.zero,
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      // To reproduce this bug:
                      //  1. Enable semantics
                      //  2. Try hitting the first option on the dropdown above
                      //
                      // You should see "Option 1 pressed" in the console.
                      // If instead you see "Submit Button pressed!", the
                      // semantics bug has been triggered.
                      Semantics(
                        container: true,
                        child: Container(
                          child: ElevatedButton(
                            onPressed: () {
                              print('Submit Button pressed!');
                            },
                            child: Text('Submit'),
                          ),
                        ),
                      ),
                      // Toggle Button
                      SizedBox(height: 20),
                      Semantics(
                        container: true,
                        child: ElevatedButton(
                          onPressed: () {
                            setState(() {
                              if (_semanticsHandle == null) {
                                _semanticsHandle =
                                    RendererBinding.instance.ensureSemantics();

                                print('Semantics enabled');
                              } else {
                                _semanticsHandle!.dispose();
                                _semanticsHandle = null;

                                print('Semantics disabled');
                              }
                            });
                          },
                          child: Text(_semanticsHandle != null
                              ? 'Disable Semantics'
                              : 'Enable Semantics'),
                        ),
                      ),
                    ],
                  ),
                )
              ]),
        )),
      ],
    );

    return AnnotatedRegion(
      value: SystemUiOverlayStyle.light,
      child: row,
    );
  }
}

```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

https://youtu.be/uqgGJ2aMyaU

</details>


### Logs

<details open><summary>Logs</summary>

```console
N/A
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[   +4 ms] ProcessManager.runSync('which java')
[   +8 ms] executing: /usr/local/buildtools/java/jdk/bin/java --version
[   +1 ms] ProcessManager.runSync('/usr/local/buildtools/java/jdk/bin/java --version')
[ +314 ms] Exit code 0 from: /usr/local/buildtools/java/jdk/bin/java --version
[   +2 ms] openjdk 11.0.20.1 2024-01-05
           OpenJDK Runtime Environment (build 11.0.20.1+1-google-release-596018471)
           OpenJDK 64-Bit Server VM (build 11.0.20.1+1-google-release-596018471, mixed mode, sharing)
[   +1 ms] executing: /usr/bin/adb devices -l
[   +1 ms] ProcessManager.run('/usr/bin/adb devices -l')
[   +1 ms] Flag --fuchsia not found, Fuchsia device discovery disabled.
[   +1 ms] Gallium device polling: connecting to galliumd.
[   +2 ms] [✓] Flutter (Channel google3, on Debian GNU/Linux rodete 6.5.13-1rodete2-amd64, locale en_US.UTF-8)
[   +1 ms]     • Framework revision 345857712f (12 days ago), 2024-02-08T00:00:00.000
[   +1 ms]     • Engine revision f9a169e0e0
[   +1 ms]     • Dart version 452dd17120
[   +1 ms] [✓] Android toolchain - develop for Android devices (Android SDK version Stable)
[   +1 ms]     • Android SDK at google3
[   +1 ms]     • Platform Stable, build-tools Stable
[   +1 ms]     • Java binary at: /usr/local/buildtools/java/jdk/bin/java
[   +1 ms]     • Java version OpenJDK Runtime Environment (build 11.0.20.1+1-google-release-596018471)
[   +1 ms] [✓] VS Code (version 1.85.1)
[   +1 ms]     • VS Code at /usr/share/code
[   +1 ms]     • Flutter extension can be installed from:
[   +1 ms]       🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[  +73 ms] List of devices attached
[   +2 ms] Gallium device polling failed to connect to galliumd: gRPC Error (code: 14, codeName: UNAVAILABLE, message: Error connecting: SocketException: Connection refused (OS Error: Connection refused, errno = 111),
address = localhost, port = 43824, details: null, rawResponse: null, trailers: {})
[   +1 ms] executing: uname -m
[   +1 ms] ProcessManager.runSync('uname -m')
[   +3 ms] Exit code 0 from: uname -m
[   +1 ms] x86_64
[   +1 ms] executing: /usr/bin/adb devices -l
[   +1 ms] ProcessManager.run('/usr/bin/adb devices -l')
[   +5 ms] List of devices attached
[   +1 ms] [✓] Connected device (1 available)
[   +1 ms]     • Linux (desktop) • linux • linux-x64 • Debian GNU/Linux rodete 6.5.13-1rodete2-amd64
[   +1 ms] [✓] Google3 (on linux)
[   +1 ms]     • KVM enabled
[   +1 ms] • No issues found!
[   +1 ms] "flutter doctor" took 454ms.
[+1094 ms] ensureAnalyticsSent: 1092ms
[   +2 ms] Running 0 shutdown hooks
[   +1 ms] Shutdown hooks complete
[   +1 ms] exiting with code 0
```

</details>