From 7f56a614171d2a172b364bddecb78e3031cff4b2 Mon Sep 17 00:00:00 2001 From: Shi-Hao Hong Date: Mon, 16 Dec 2019 16:40:15 -0800 Subject: [PATCH] Fix isDense default for DropdownButtonFormField (#47160) --- .../flutter/lib/src/material/dropdown.dart | 2 +- .../material/dropdown_form_field_test.dart | 36 +++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index 4edeffbd33..9b23a687f1 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -1402,7 +1402,7 @@ class DropdownButtonFormField extends FormField { Color iconDisabledColor, Color iconEnabledColor, double iconSize = 24.0, - bool isDense = false, + bool isDense = true, bool isExpanded = false, double itemHeight, }) : assert(items == null || items.isEmpty || value == null || diff --git a/packages/flutter/test/material/dropdown_form_field_test.dart b/packages/flutter/test/material/dropdown_form_field_test.dart index c67bee5e2b..41ba8c85f9 100644 --- a/packages/flutter/test/material/dropdown_form_field_test.dart +++ b/packages/flutter/test/material/dropdown_form_field_test.dart @@ -13,6 +13,10 @@ import '../rendering/mock_canvas.dart'; const List menuItems = ['one', 'two', 'three', 'four']; final ValueChanged onChanged = (_) { }; +final Type dropdownButtonType = DropdownButton( + onChanged: (_) { }, + items: const >[], +).runtimeType; Finder _iconRichText(Key iconKey) { return find.descendant( @@ -31,7 +35,7 @@ Widget buildFormFrame({ Color iconDisabledColor, Color iconEnabledColor, double iconSize = 24.0, - bool isDense = false, + bool isDense = true, bool isExpanded = false, Widget hint, Widget disabledHint, @@ -227,7 +231,6 @@ void main() { buildFormFrame( buttonKey: buttonKey, value: value, - isDense: true, onChanged: onChanged, ), ); @@ -262,6 +265,35 @@ void main() { } }); + testWidgets('DropdownButtonFormField.isDense is true by default', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/46844 + final Key buttonKey = UniqueKey(); + const String value = 'two'; + + await tester.pumpWidget( + TestApp( + textDirection: TextDirection.ltr, + child: Material( + 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')), + ); + }).toList(), + ), + ), + ), + ); + + final RenderBox box = tester.renderObject(find.byType(dropdownButtonType)); + expect(box.size.height, 24.0); + }); + testWidgets('DropdownButtonFormField - custom text style', (WidgetTester tester) async { const String value = 'foo'; final UniqueKey itemKey = UniqueKey();