Repository: flutter
Issue: [Flutter Web] dialogs dismissed prematurely with ensureSemantics
Labels: a: accessibility,platform-web,has reproducible steps,P2,team-web,triaged-web,found in release: 3.22,found in release: 3.23

### Steps to reproduce

1. Run the code sample as a Web project in Chrome. 
2. Click on the "Show Dialog" button. 
3. Click anywhere inside the dialog that is not a form field. 
4. Observe the dialog being dismissed.

### Expected results

The dialog should not dismiss when any content inside it is clicked. The dialog should only dismiss if the area outside the content (the barrier) is clicked. It works as expected in MacOS builds.

### Actual results

Clicking on whitespace inside the dialog causes it to be dismissed in Web builds. This only occurs in Web builds and only when `WidgetsFlutterBinding.ensureInitialized().ensureSemantics();` is included.

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
  WidgetsFlutterBinding.ensureInitialized().ensureSemantics();
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Semantics Issue',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  void _onPressed() {
    showDialog(
      context: context,
      barrierColor: Colors.grey.shade400,
      builder: (context) {
        return _dialogContent;
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            FilledButton(
              onPressed: _onPressed,
              child: const Text('Show Dialog'),
            )
          ],
        ),
      ),
    );
  }

  Widget get _dialogContent => Center(
        child: Container(
          margin: const EdgeInsets.all(50),
          child: const Material(
            child: SizedBox(
              height: 250,
              width: 250,
              child: Padding(
                padding: EdgeInsets.all(20),
                child: Column(
                  children: [
                    TextField(
                      decoration: InputDecoration(
                        border: OutlineInputBorder(),
                        labelText: 'Form field one',
                      ),
                    ),
                    SizedBox(height: 40),
                    TextField(
                      decoration: InputDecoration(
                        border: OutlineInputBorder(),
                        labelText: 'Form field two',
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),
      );
    }
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>


https://github.com/flutter/flutter/assets/1129265/fa9f2bce-0346-441e-ace7-905532ec23f2



</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.19.2, on macOS 14.2.1 23C71 darwin-arm64, locale en-US)
    • Flutter version 3.19.2 on channel stable at /Users/rona/Sites/Tools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7482962148 (3 months ago), 2024-02-27 16:51:22 -0500
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.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 15.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15E204a
    ✗ Unable to get list of installed Simulator runtimes.
    • CocoaPods version 1.15.2

[✓] 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).

[✓] VS Code (version 1.89.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.88.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 14.2.1 23C71 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 125.0.6422.76

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 3 categories.
```

</details>