mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Update DropdownButton underline to be customizable (#29138)
This commit is contained in:
parent
a4b9ef2e79
commit
db096cdfd8
@ -599,6 +599,7 @@ class DropdownButton<T> extends StatefulWidget {
|
||||
@required this.onChanged,
|
||||
this.elevation = 8,
|
||||
this.style,
|
||||
this.underline,
|
||||
this.icon,
|
||||
this.iconDisabledColor,
|
||||
this.iconEnabledColor,
|
||||
@ -656,6 +657,11 @@ class DropdownButton<T> 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<T> extends State<DropdownButton<T>> 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))
|
||||
|
||||
@ -39,6 +39,7 @@ Widget buildFrame({
|
||||
bool isExpanded = false,
|
||||
Widget hint,
|
||||
Widget disabledHint,
|
||||
Widget underline,
|
||||
List<String> 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<DropdownMenuItem<String>>((String item) {
|
||||
return DropdownMenuItem<String>(
|
||||
key: ValueKey<String>(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>(decoratedBox).decoration, decoration);
|
||||
|
||||
await tester.pumpWidget(buildFrame(buttonKey: buttonKey, value: 'two', onChanged: onChanged));
|
||||
expect(tester.widget<DecoratedBox>(decoratedBox).decoration, defaultDecoration);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user