From 74ac86788237e3d15f5a5c174c6d6bbe526ad82c Mon Sep 17 00:00:00 2001 From: Foong Siqi <65641198+foongsq@users.noreply.github.com> Date: Wed, 20 Jul 2022 06:42:04 +0800 Subject: [PATCH] Modify calculation of dense button height when text scale is large for dropdown button (#107201) --- .../flutter/lib/src/material/dropdown.dart | 4 +- .../material/dropdown_form_field_test.dart | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index 956ba3d5f9..de372bba1c 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -1331,8 +1331,10 @@ class _DropdownButtonState extends State> with WidgetsBindi // Similarly, we don't reduce the height of the button so much that its icon // would be clipped. double get _denseButtonHeight { + final double textScaleFactor = MediaQuery.of(context).textScaleFactor; final double fontSize = _textStyle!.fontSize ?? Theme.of(context).textTheme.subtitle1!.fontSize!; - return math.max(fontSize, math.max(widget.iconSize, _kDenseButtonHeight)); + final double scaledFontSize = textScaleFactor * fontSize; + return math.max(scaledFontSize, math.max(widget.iconSize, _kDenseButtonHeight)); } Color get _iconColor { diff --git a/packages/flutter/test/material/dropdown_form_field_test.dart b/packages/flutter/test/material/dropdown_form_field_test.dart index bb0a111909..e53f69fa4b 100644 --- a/packages/flutter/test/material/dropdown_form_field_test.dart +++ b/packages/flutter/test/material/dropdown_form_field_test.dart @@ -567,6 +567,45 @@ void main() { } }); + testWidgets('DropdownButtonFormField with isDense:true does not clip large scale text', + (WidgetTester tester) async { + final Key buttonKey = UniqueKey(); + const String value = 'two'; + + await tester.pumpWidget( + TestApp( + textDirection: TextDirection.ltr, + child: Builder( + builder: (BuildContext context) => MediaQuery( + data: MediaQuery.of(context).copyWith(textScaleFactor: 3.0), + child: Material( + child: Center( + child: DropdownButtonFormField( + key: buttonKey, + value: value, + onChanged: onChanged, + items: menuItems.map>((String item) { + return DropdownMenuItem( + key: ValueKey(item), + value: item, + child: Text(item, + key: ValueKey('${item}Text'), + style: const TextStyle(fontSize: 20.0)), + ); + }).toList(), + ), + ), + ), + ), + ), + ), + ); + + final RenderBox box = + tester.renderObject(find.byType(dropdownButtonType)); + expect(box.size.height, 72.0); + }); + testWidgets('DropdownButtonFormField.isDense is true by default', (WidgetTester tester) async { // Regression test for https://github.com/flutter/flutter/issues/46844 final Key buttonKey = UniqueKey();