From db096cdfd84851ccbd39f57f4af44d36ea28729e Mon Sep 17 00:00:00 2001 From: Shayne Kelly II Date: Thu, 21 Mar 2019 10:32:43 -0700 Subject: [PATCH] Update DropdownButton underline to be customizable (#29138) --- .../flutter/lib/src/material/dropdown.dart | 8 +++++- .../flutter/test/material/dropdown_test.dart | 28 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index 5afc7e3acb0..904a790ad2c 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -599,6 +599,7 @@ class DropdownButton extends StatefulWidget { @required this.onChanged, this.elevation = 8, this.style, + this.underline, this.icon, this.iconDisabledColor, this.iconEnabledColor, @@ -656,6 +657,11 @@ class DropdownButton extends StatefulWidget { /// [ThemeData.textTheme] of the current [Theme]. final TextStyle style; + /// The widget to use for drawing the drop-down button's underline. + /// + /// Defaults to a 0.0 width bottom border with color 0xFFBDBDBD. + final Widget underline; + /// The widget to use for the drop-down button's icon. /// /// Defaults to an [Icon] with the [Icons.arrow_drop_down] glyph. @@ -897,7 +903,7 @@ class _DropdownButtonState extends State> with WidgetsBindi left: 0.0, right: 0.0, bottom: bottom, - child: Container( + child: widget.underline ?? Container( height: 1.0, decoration: const BoxDecoration( border: Border(bottom: BorderSide(color: Color(0xFFBDBDBD), width: 0.0)) diff --git a/packages/flutter/test/material/dropdown_test.dart b/packages/flutter/test/material/dropdown_test.dart index b70fd241030..a5730c66c6e 100644 --- a/packages/flutter/test/material/dropdown_test.dart +++ b/packages/flutter/test/material/dropdown_test.dart @@ -39,6 +39,7 @@ Widget buildFrame({ bool isExpanded = false, Widget hint, Widget disabledHint, + Widget underline, List items = menuItems, Alignment alignment = Alignment.center, TextDirection textDirection = TextDirection.ltr, @@ -61,6 +62,7 @@ Widget buildFrame({ iconEnabledColor: iconEnabledColor, isDense: isDense, isExpanded: isExpanded, + underline: underline, items: items == null ? null : items.map>((String item) { return DropdownMenuItem( key: ValueKey(item), @@ -1223,4 +1225,30 @@ void main() { await tester.pumpAndSettle(); expect(selectedIndex, 13); }); + + testWidgets('Dropdown button will accept widgets as its underline', ( + WidgetTester tester) async { + + const BoxDecoration decoration = BoxDecoration( + border: Border(bottom: BorderSide(color: Color(0xFFCCBB00), width: 4.0)), + ); + const BoxDecoration defaultDecoration = BoxDecoration( + border: Border(bottom: BorderSide(color: Color(0xFFBDBDBD), width: 0.0)), + ); + + final Widget customUnderline = Container(height: 4.0, decoration: decoration); + final Key buttonKey = UniqueKey(); + + final Finder decoratedBox = find.descendant( + of: find.byKey(buttonKey), + matching: find.byType(DecoratedBox), + ); + + await tester.pumpWidget(buildFrame(buttonKey: buttonKey, underline: customUnderline, + value: 'two', onChanged: onChanged)); + expect(tester.widget(decoratedBox).decoration, decoration); + + await tester.pumpWidget(buildFrame(buttonKey: buttonKey, value: 'two', onChanged: onChanged)); + expect(tester.widget(decoratedBox).decoration, defaultDecoration); + }); }