Repository: flutter
Issue: [bug] DropdownMenu that is open does not close upon a system back gesture
Labels: platform-android,framework,f: material design,has reproducible steps,P2,team-design,triaged-design,found in release: 3.22,found in release: 3.23

### Steps to reproduce

When pressing the Android Back button while having a DropdownMenu open, the app is closed, rather than closing the dropdown Menu. This is in contrast to the Material 2 version, DropdownButton, where when open, if the Android Back button is opened, the dropdown menu is closed.

I have gone through the material 3 spec for the dropdown, and it haven't found that the dropdown shouldn't be closed upon doing the system back gesture.

Note that in the video attached, I am using an emulator for recording purposes. This is also happening on actual devices.

To replicate

1. Tap on the DropdownMenu to open
2. Tap on the Android Back button

### Expected results

When the user taps the android back button, the dropdown menu should be closed, rather than closing the entire app / screen.

This is to be consistent with the functionality of the DropdownButton widget, which closes the Dropdown upon pressing the android back button.

### Actual results

- If Dropdown Menu is opened at the base route, pressing android back button closes the app (as in video)

- If DropdownMenu is open while on secondary route, the route is popped (Similar to calling Navigator.pop) 

- If DropdownMenu is open while in a Bottom Sheet, pressing the Android Back button closes both the menu and bottom sheet

### 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: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            DropdownButton(
              items: [
                DropdownMenuItem(child: Text('Dropdown button 1'), value: 1),
                DropdownMenuItem(child: Text('Dropdown button 2'), value: 2),
                DropdownMenuItem(child: Text('Dropdown button 3'), value: 3),
              ],
              onChanged: (value) {},
            ),
            const SizedBox(
              height: 24,
            ),
            DropdownMenu<int>(
              enableSearch: false,
              label: const Text('This is a dropdown menu'),
              width: MediaQuery.of(context).size.width - 32,
              dropdownMenuEntries: const [
                DropdownMenuEntry<int>(
                  value: 1,
                  label: 'Dropdown menu 1',
                ),
                DropdownMenuEntry<int>(
                  value: 2,
                  label: 'Dropdown menu 2',
                ),
                DropdownMenuEntry<int>(
                  value: 3,
                  label: 'Dropdown menu 3',
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>


https://github.com/flutter/flutter/assets/7465421/e184494b-b373-4fc5-be29-8a49b272091b


</details>


### Logs

_No response_

### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.22.2, on macOS 14.5 23F79 darwin-arm64, locale
    en-MT)
    • Flutter version 3.22.2 on channel stable at
      <user path>/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 761747bfc5 (3 weeks ago), 2024-06-05 22:15:13 +0200
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at <user path>/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.10+0-17.0.10b1087.21-11572160)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.15.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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-17.0.10b1087.21-11572160)

[✓] Connected device (5 available)
    • sdk gphone64 arm64 (mobile)     • emulator-5554                        •
      android-arm64  • Android 14 (API 34) (emulator)
    • iPhone 13 (mobile)              •  •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
    • macOS (desktop)                 • macos                                •
      darwin-arm64   • macOS 14.5 23F79 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                •
      darwin         • macOS 14.5 23F79 darwin-arm64
    • Chrome (web)                    • chrome                               •
      web-javascript • Google Chrome 126.0.6478.114

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>