Wire selectedItemBuilder through DropdownButtonFormField (#44160)
This commit is contained in:
@@ -1299,6 +1299,7 @@ class DropdownButtonFormField<T> extends FormField<T> {
|
|||||||
Key key,
|
Key key,
|
||||||
T value,
|
T value,
|
||||||
@required List<DropdownMenuItem<T>> items,
|
@required List<DropdownMenuItem<T>> items,
|
||||||
|
DropdownButtonBuilder selectedItemBuilder,
|
||||||
Widget hint,
|
Widget hint,
|
||||||
@required this.onChanged,
|
@required this.onChanged,
|
||||||
this.decoration = const InputDecoration(),
|
this.decoration = const InputDecoration(),
|
||||||
@@ -1347,6 +1348,7 @@ class DropdownButtonFormField<T> extends FormField<T> {
|
|||||||
child: DropdownButton<T>(
|
child: DropdownButton<T>(
|
||||||
value: value,
|
value: value,
|
||||||
items: items,
|
items: items,
|
||||||
|
selectedItemBuilder: selectedItemBuilder,
|
||||||
hint: hint,
|
hint: hint,
|
||||||
onChanged: onChanged == null ? null : field.didChange,
|
onChanged: onChanged == null ? null : field.didChange,
|
||||||
disabledHint: disabledHint,
|
disabledHint: disabledHint,
|
||||||
|
|||||||
@@ -586,4 +586,48 @@ void main() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('DropdownButtonFormField - selectedItemBuilder builds custom buttons', (WidgetTester tester) async {
|
||||||
|
const List<String> items = <String>[
|
||||||
|
'One',
|
||||||
|
'Two',
|
||||||
|
'Three',
|
||||||
|
];
|
||||||
|
String selectedItem = items[0];
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
StatefulBuilder(
|
||||||
|
builder: (BuildContext context, StateSetter setState) {
|
||||||
|
return MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: DropdownButtonFormField<String>(
|
||||||
|
value: selectedItem,
|
||||||
|
onChanged: (String string) => setState(() => selectedItem = string),
|
||||||
|
selectedItemBuilder: (BuildContext context) {
|
||||||
|
int index = 0;
|
||||||
|
return items.map((String string) {
|
||||||
|
index += 1;
|
||||||
|
return Text('$string as an Arabic numeral: $index');
|
||||||
|
}).toList();
|
||||||
|
},
|
||||||
|
items: items.map((String string) {
|
||||||
|
return DropdownMenuItem<String>(
|
||||||
|
child: Text(string),
|
||||||
|
value: string,
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.text('One as an Arabic numeral: 1'), findsOneWidget);
|
||||||
|
await tester.tap(find.text('One as an Arabic numeral: 1'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.tap(find.text('Two'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Two as an Arabic numeral: 2'), findsOneWidget);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user