mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
fix DropdownMenu overflow (#147233)
fix `DropdownMenu` overflow issue in https://github.com/flutter/flutter/issues/147076 and https://github.com/flutter/flutter/issues/147173 However I believe the the menu placement issue in https://github.com/flutter/flutter/issues/147076 is a separate issue. It is not fixed here. fixes https://github.com/flutter/flutter/issues/147173
This commit is contained in:
parent
f256f68831
commit
68f8b536e2
@ -905,9 +905,11 @@ class _RenderDropdownMenuBody extends RenderBox
|
|||||||
double? maxHeight;
|
double? maxHeight;
|
||||||
RenderBox? child = firstChild;
|
RenderBox? child = firstChild;
|
||||||
|
|
||||||
|
final double intrinsicWidth = width ?? getMaxIntrinsicWidth(constraints.maxHeight);
|
||||||
|
final double widthConstraint = math.min(intrinsicWidth, constraints.maxWidth);
|
||||||
final BoxConstraints innerConstraints = BoxConstraints(
|
final BoxConstraints innerConstraints = BoxConstraints(
|
||||||
maxWidth: width ?? getMaxIntrinsicWidth(constraints.maxWidth),
|
maxWidth: widthConstraint,
|
||||||
maxHeight: getMaxIntrinsicHeight(constraints.maxHeight),
|
maxHeight: getMaxIntrinsicHeight(widthConstraint),
|
||||||
);
|
);
|
||||||
while (child != null) {
|
while (child != null) {
|
||||||
if (child == firstChild) {
|
if (child == firstChild) {
|
||||||
@ -947,9 +949,11 @@ class _RenderDropdownMenuBody extends RenderBox
|
|||||||
double maxWidth = 0.0;
|
double maxWidth = 0.0;
|
||||||
double? maxHeight;
|
double? maxHeight;
|
||||||
RenderBox? child = firstChild;
|
RenderBox? child = firstChild;
|
||||||
|
final double intrinsicWidth = width ?? getMaxIntrinsicWidth(constraints.maxHeight);
|
||||||
|
final double widthConstraint = math.min(intrinsicWidth, constraints.maxWidth);
|
||||||
final BoxConstraints innerConstraints = BoxConstraints(
|
final BoxConstraints innerConstraints = BoxConstraints(
|
||||||
maxWidth: width ?? getMaxIntrinsicWidth(constraints.maxWidth),
|
maxWidth: widthConstraint,
|
||||||
maxHeight: getMaxIntrinsicHeight(constraints.maxHeight),
|
maxHeight: getMaxIntrinsicHeight(widthConstraint),
|
||||||
);
|
);
|
||||||
|
|
||||||
while (child != null) {
|
while (child != null) {
|
||||||
|
@ -2129,6 +2129,60 @@ void main() {
|
|||||||
// No exception should be thrown.
|
// No exception should be thrown.
|
||||||
expect(tester.takeException(), isNull);
|
expect(tester.takeException(), isNull);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// This is a regression test for https://github.com/flutter/flutter/issues/147076.
|
||||||
|
testWidgets('Text field does not overflow parent', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: SizedBox(
|
||||||
|
width: 300,
|
||||||
|
child: DropdownMenu<int>(
|
||||||
|
dropdownMenuEntries: <DropdownMenuEntry<int>>[
|
||||||
|
DropdownMenuEntry<int>(
|
||||||
|
value: 0,
|
||||||
|
label: 'This is a long text that is multiplied by 4 so it can overflow. ' * 4,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
await tester.pump();
|
||||||
|
final RenderBox box = tester.firstRenderObject(find.byType(TextField));
|
||||||
|
expect(box.size.width, 300.0);
|
||||||
|
});
|
||||||
|
|
||||||
|
// This is a regression test for https://github.com/flutter/flutter/issues/147173.
|
||||||
|
testWidgets('Text field with large helper text can be selected', (WidgetTester tester) async {
|
||||||
|
const String labelText = 'MenuEntry 1';
|
||||||
|
await tester.pumpWidget(const MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: Center(
|
||||||
|
child: DropdownMenu<int>(
|
||||||
|
hintText: 'Hint text',
|
||||||
|
helperText: 'Menu Helper text',
|
||||||
|
inputDecorationTheme: InputDecorationTheme(
|
||||||
|
helperMaxLines: 2,
|
||||||
|
helperStyle: TextStyle(fontSize: 30),
|
||||||
|
),
|
||||||
|
dropdownMenuEntries: <DropdownMenuEntry<int>>[
|
||||||
|
DropdownMenuEntry<int>(
|
||||||
|
value: 0,
|
||||||
|
label: labelText,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
await tester.pump();
|
||||||
|
await tester.tapAt(tester.getCenter(find.text('Hint text')));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
// One is layout for the _DropdownMenuBody, the other one is the real button item in the menu.
|
||||||
|
expect(find.widgetWithText(MenuItemButton, labelText), findsNWidgets(2));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
enum TestMenu {
|
enum TestMenu {
|
||||||
|
Loading…
Reference in New Issue
Block a user