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.
This commit is contained in:
parent
79ae04d4ed
commit
252a14ba2f
@ -795,7 +795,8 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> 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 {
|
||||
|
@ -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<String>(
|
||||
value: value,
|
||||
items: <DropdownMenuItem<String>>[
|
||||
DropdownMenuItem<String>(
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user