Unverified Commit 7f56a614 authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

Fix isDense default for DropdownButtonFormField (#47160)

parent 1871c61f
...@@ -1402,7 +1402,7 @@ class DropdownButtonFormField<T> extends FormField<T> { ...@@ -1402,7 +1402,7 @@ class DropdownButtonFormField<T> extends FormField<T> {
Color iconDisabledColor, Color iconDisabledColor,
Color iconEnabledColor, Color iconEnabledColor,
double iconSize = 24.0, double iconSize = 24.0,
bool isDense = false, bool isDense = true,
bool isExpanded = false, bool isExpanded = false,
double itemHeight, double itemHeight,
}) : assert(items == null || items.isEmpty || value == null || }) : assert(items == null || items.isEmpty || value == null ||
......
...@@ -13,6 +13,10 @@ import '../rendering/mock_canvas.dart'; ...@@ -13,6 +13,10 @@ import '../rendering/mock_canvas.dart';
const List<String> menuItems = <String>['one', 'two', 'three', 'four']; const List<String> menuItems = <String>['one', 'two', 'three', 'four'];
final ValueChanged<String> onChanged = (_) { }; final ValueChanged<String> onChanged = (_) { };
final Type dropdownButtonType = DropdownButton<String>(
onChanged: (_) { },
items: const <DropdownMenuItem<String>>[],
).runtimeType;
Finder _iconRichText(Key iconKey) { Finder _iconRichText(Key iconKey) {
return find.descendant( return find.descendant(
...@@ -31,7 +35,7 @@ Widget buildFormFrame({ ...@@ -31,7 +35,7 @@ Widget buildFormFrame({
Color iconDisabledColor, Color iconDisabledColor,
Color iconEnabledColor, Color iconEnabledColor,
double iconSize = 24.0, double iconSize = 24.0,
bool isDense = false, bool isDense = true,
bool isExpanded = false, bool isExpanded = false,
Widget hint, Widget hint,
Widget disabledHint, Widget disabledHint,
...@@ -227,7 +231,6 @@ void main() { ...@@ -227,7 +231,6 @@ void main() {
buildFormFrame( buildFormFrame(
buttonKey: buttonKey, buttonKey: buttonKey,
value: value, value: value,
isDense: true,
onChanged: onChanged, onChanged: onChanged,
), ),
); );
...@@ -262,6 +265,35 @@ void main() { ...@@ -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<String>(
key: buttonKey,
value: value,
onChanged: onChanged,
items: menuItems.map<DropdownMenuItem<String>>((String item) {
return DropdownMenuItem<String>(
key: ValueKey<String>(item),
value: item,
child: Text(item, key: ValueKey<String>(item + 'Text')),
);
}).toList(),
),
),
),
);
final RenderBox box = tester.renderObject<RenderBox>(find.byType(dropdownButtonType));
expect(box.size.height, 24.0);
});
testWidgets('DropdownButtonFormField - custom text style', (WidgetTester tester) async { testWidgets('DropdownButtonFormField - custom text style', (WidgetTester tester) async {
const String value = 'foo'; const String value = 'foo';
final UniqueKey itemKey = UniqueKey(); final UniqueKey itemKey = UniqueKey();
......
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