From 252a14ba2ffae83a6fff2032f0e435b89cc7f198 Mon Sep 17 00:00:00 2001 From: Darren Austin Date: Wed, 29 May 2019 13:18:34 -0700 Subject: [PATCH] Fixed for DropdownButton crashing when a style was used that didn't include a fontSize (#33474) Fixed an issue with a DropdownButton crashing when a style was used that didn't include a fontSize. --- .../flutter/lib/src/material/dropdown.dart | 3 ++- .../flutter/test/material/dropdown_test.dart | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index 904a790ad2..18b29f5db7 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -795,7 +795,8 @@ 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 { - return math.max(_textStyle.fontSize, math.max(widget.iconSize, _kDenseButtonHeight)); + final double fontSize = _textStyle.fontSize ?? Theme.of(context).textTheme.subhead.fontSize; + return math.max(fontSize, math.max(widget.iconSize, _kDenseButtonHeight)); } Color get _iconColor { diff --git a/packages/flutter/test/material/dropdown_test.dart b/packages/flutter/test/material/dropdown_test.dart index a5730c66c6..382cdeee2a 100644 --- a/packages/flutter/test/material/dropdown_test.dart +++ b/packages/flutter/test/material/dropdown_test.dart @@ -612,6 +612,33 @@ void main() { checkSelectedItemTextGeometry(tester, 'two'); }); + testWidgets('Dropdown button can have a text style with no fontSize specified', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/33425 + const String value = 'foo'; + final UniqueKey itemKey = UniqueKey(); + + await tester.pumpWidget(TestApp( + textDirection: TextDirection.ltr, + child: Material( + child: DropdownButton( + value: value, + items: >[ + DropdownMenuItem( + key: itemKey, + value: 'foo', + child: const Text(value), + ), + ], + isDense: true, + onChanged: (_) { }, + style: const TextStyle(color: Colors.blue), + ), + ), + )); + + expect(tester.takeException(), isNull); + }); + testWidgets('Dropdown menu scrolls to first item in long lists', (WidgetTester tester) async { // Open the dropdown menu final Key buttonKey = UniqueKey();