mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
## Description
This PR fixes DropdownMenu menu panel being shorter than the TextField
when it expands to full-screen width.
## Before
The menu panel is shorter than the text field:
<img width="297" height="130" alt="image"
src="https://github.com/user-attachments/assets/db42bd01-94d8-47fb-9331-ebd78111b931"
/>
## After
The menu panel expands as close as possible to the edge similarly to the
text field.
<img width="297" height="130" alt="image"
src="https://github.com/user-attachments/assets/b7d8f2aa-a668-439a-8195-9b9ce48dba6b"
/>
## Code sample
<details><summary>Code sample for recordings</summary>
```dart
import 'package:flutter/material.dart';
void main() {
runApp(const DropdownMenuExample());
}
class DropdownMenuExample extends StatefulWidget {
const DropdownMenuExample({super.key});
@override
State<DropdownMenuExample> createState() => _DropdownMenuExampleState();
}
class _DropdownMenuExampleState extends State<DropdownMenuExample> {
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: DropdownMenu<int>(
expandedInsets: EdgeInsets.zero,
dropdownMenuEntries: <DropdownMenuEntry<int>>[
DropdownMenuEntry<int>(value: 0, label: 'Flutter'),
],
),
),
);
}
}
```
</details>
## Implementation details
MenuAnchor automatically adds a default padding, see
2c21273bfd/packages/flutter/lib/src/material/menu_anchor.dart (L81-L82)
This PR add a property to menu anchor to expose the view padding.
DropdownMenu sets this padding to EdgeInsets.zero to opt-out from the
default 8 padding.
## Related Issue
Fixes [DropdownMenu children is shorter than the TextField when it
expands to full-screen
width](https://github.com/flutter/flutter/issues/172680)
## Tests
Adds 2 tests.
---------
Co-authored-by: Qun Cheng <36861262+QuncCccccc@users.noreply.github.com>
Flutter
Flutter is a new way to build high-performance, cross-platform mobile, web, and desktop apps. Flutter is optimized for today's — and tomorrow's — mobile and desktop devices. We are focused on low-latency input and high frame rates on all platforms.
See the getting started guide for information about using Flutter.