Commit db096cdf authored by Shayne Kelly II's avatar Shayne Kelly II Committed by Hans Muller

Update DropdownButton underline to be customizable (#29138)

parent a4b9ef2e
...@@ -599,6 +599,7 @@ class DropdownButton<T> extends StatefulWidget { ...@@ -599,6 +599,7 @@ class DropdownButton<T> extends StatefulWidget {
@required this.onChanged, @required this.onChanged,
this.elevation = 8, this.elevation = 8,
this.style, this.style,
this.underline,
this.icon, this.icon,
this.iconDisabledColor, this.iconDisabledColor,
this.iconEnabledColor, this.iconEnabledColor,
...@@ -656,6 +657,11 @@ class DropdownButton<T> extends StatefulWidget { ...@@ -656,6 +657,11 @@ class DropdownButton<T> extends StatefulWidget {
/// [ThemeData.textTheme] of the current [Theme]. /// [ThemeData.textTheme] of the current [Theme].
final TextStyle style; 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. /// The widget to use for the drop-down button's icon.
/// ///
/// Defaults to an [Icon] with the [Icons.arrow_drop_down] glyph. /// Defaults to an [Icon] with the [Icons.arrow_drop_down] glyph.
...@@ -897,7 +903,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi ...@@ -897,7 +903,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
left: 0.0, left: 0.0,
right: 0.0, right: 0.0,
bottom: bottom, bottom: bottom,
child: Container( child: widget.underline ?? Container(
height: 1.0, height: 1.0,
decoration: const BoxDecoration( decoration: const BoxDecoration(
border: Border(bottom: BorderSide(color: Color(0xFFBDBDBD), width: 0.0)) border: Border(bottom: BorderSide(color: Color(0xFFBDBDBD), width: 0.0))
......
...@@ -39,6 +39,7 @@ Widget buildFrame({ ...@@ -39,6 +39,7 @@ Widget buildFrame({
bool isExpanded = false, bool isExpanded = false,
Widget hint, Widget hint,
Widget disabledHint, Widget disabledHint,
Widget underline,
List<String> items = menuItems, List<String> items = menuItems,
Alignment alignment = Alignment.center, Alignment alignment = Alignment.center,
TextDirection textDirection = TextDirection.ltr, TextDirection textDirection = TextDirection.ltr,
...@@ -61,6 +62,7 @@ Widget buildFrame({ ...@@ -61,6 +62,7 @@ Widget buildFrame({
iconEnabledColor: iconEnabledColor, iconEnabledColor: iconEnabledColor,
isDense: isDense, isDense: isDense,
isExpanded: isExpanded, isExpanded: isExpanded,
underline: underline,
items: items == null ? null : items.map<DropdownMenuItem<String>>((String item) { items: items == null ? null : items.map<DropdownMenuItem<String>>((String item) {
return DropdownMenuItem<String>( return DropdownMenuItem<String>(
key: ValueKey<String>(item), key: ValueKey<String>(item),
...@@ -1223,4 +1225,30 @@ void main() { ...@@ -1223,4 +1225,30 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(selectedIndex, 13); 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>(decoratedBox).decoration, decoration);
await tester.pumpWidget(buildFrame(buttonKey: buttonKey, value: 'two', onChanged: onChanged));
expect(tester.widget<DecoratedBox>(decoratedBox).decoration, defaultDecoration);
});
} }
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