Unverified Commit db5434e5 authored by Qun Cheng's avatar Qun Cheng Committed by GitHub

Fix menu width issue for `DropdownMenu` (#123823)

parent e6c2abb0
......@@ -19,6 +19,7 @@ import 'menu_anchor.dart';
import 'menu_style.dart';
import 'text_field.dart';
import 'theme.dart';
import 'theme_data.dart';
// Navigation shortcuts to move the selected menu items up or down.
......@@ -535,10 +536,10 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
);
return _DropdownMenuBody(
key: _anchorKey,
width: widget.width,
children: <Widget>[
TextField(
key: _anchorKey,
mouseCursor: effectiveMouseCursor,
canRequestFocus: canRequestFocus(),
enableInteractiveSelection: canRequestFocus(),
......@@ -607,7 +608,6 @@ class _ArrowDownIntent extends Intent {
class _DropdownMenuBody extends MultiChildRenderObjectWidget {
const _DropdownMenuBody({
super.key,
super.children,
this.width,
});
......@@ -826,6 +826,7 @@ class _DropdownMenuDefaultsM3 extends DropdownMenuThemeData {
return const MenuStyle(
minimumSize: MaterialStatePropertyAll<Size>(Size(_kMinimumWidth, 0.0)),
maximumSize: MaterialStatePropertyAll<Size>(Size.infinite),
visualDensity: VisualDensity.standard,
);
}
......
......@@ -1058,6 +1058,58 @@ void main() {
await gesture.moveTo(tester.getCenter(textFieldFinder));
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
});
testWidgets('The menu has the same width as the input field in ListView', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/123631
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: ListView(
children: <Widget>[
DropdownMenu<TestMenu>(
dropdownMenuEntries: menuChildren,
),
],
),
),
));
final Rect textInput = tester.getRect(find.byType(TextField));
await tester.tap(find.byType(TextField));
await tester.pumpAndSettle();
final Finder findMenu = find.byWidgetPredicate((Widget widget) {
return widget.runtimeType.toString() == '_MenuPanel';
});
final Rect menu = tester.getRect(findMenu);
expect(textInput.width, menu.width);
await tester.pumpWidget(Container());
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: ListView(
children: <Widget>[
DropdownMenu<TestMenu>(
width: 200,
dropdownMenuEntries: menuChildren,
),
],
),
),
));
final Rect textInput1 = tester.getRect(find.byType(TextField));
await tester.tap(find.byType(TextField));
await tester.pumpAndSettle();
final Finder findMenu1 = find.byWidgetPredicate((Widget widget) {
return widget.runtimeType.toString() == '_MenuPanel';
});
final Rect menu1 = tester.getRect(findMenu1);
expect(textInput1.width, 200);
expect(menu1.width, 200);
});
}
enum TestMenu {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment