mirror of
https://github.com/flutter/flutter
synced 2024-08-27 12:00:58 +00:00
Fix menu width issue for DropdownMenu
(#123823)
This commit is contained in:
parent
e6c2abb084
commit
db5434e566
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue