Skip to content

Commit cf6d370

Browse files
authored
Merge pull request #403 from AhmedLSayed9/accept_iterable_in_properties
Accept `Iterable` instead of `List` for `selectedItemBuilder` and `multiValueListenable` properties
2 parents 35bb303 + 5763e40 commit cf6d370

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

packages/dropdown_button2/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## UNRELEASED
2+
3+
- Accept `Iterable` instead of `List` for `selectedItemBuilder` and `multiValueListenable` properties.
4+
15
## 3.0.0-beta.23
26

37
- Avoid dropdown internal FocusNode listener leak when replaced by an external FocusNode.

packages/dropdown_button2/lib/src/dropdown_button2.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ const EdgeInsets _kMenuItemPadding = EdgeInsets.symmetric(horizontal: 16.0);
2828
const EdgeInsetsGeometry _kAlignedButtonPadding = EdgeInsetsDirectional.only(start: 16.0, end: 4.0);
2929
const EdgeInsets _kUnalignedButtonPadding = EdgeInsets.zero;
3030

31+
/// A builder to customize dropdown buttons.
32+
///
33+
/// Used by [DropdownButton2.selectedItemBuilder].
34+
typedef DropdownButton2Builder = Iterable<Widget> Function(BuildContext context);
35+
3136
/// A builder to customize the selected menu item.
3237
typedef SelectedMenuItemBuilder = Widget Function(BuildContext context, Widget child);
3338

@@ -191,7 +196,7 @@ class DropdownButton2<T> extends StatefulWidget {
191196
///
192197
/// If this callback is null, the [DropdownItem] from [items]
193198
/// that matches the selected [DropdownItem]'s value will be displayed.
194-
final DropdownButtonBuilder? selectedItemBuilder;
199+
final DropdownButton2Builder? selectedItemBuilder;
195200

196201
/// A [ValueListenable] that represents the value of the currently selected [DropdownItem].
197202
/// It holds a value of type `T?`, where `T` represents the type of [DropdownItem]'s value.
@@ -213,7 +218,7 @@ class DropdownButton2<T> extends StatefulWidget {
213218
/// If the list is empty and the button is disabled, [disabledHint] will be displayed
214219
/// if it is non-null. If [disabledHint] is null, then [hint] will be displayed
215220
/// if it is non-null.
216-
final ValueListenable<List<T>>? multiValueListenable;
221+
final ValueListenable<Iterable<T>>? multiValueListenable;
217222

218223
/// A placeholder widget that is displayed by the dropdown button.
219224
///
@@ -1021,9 +1026,9 @@ class DropdownButtonFormField2<T> extends FormField<T> {
10211026
DropdownButtonFormField2({
10221027
super.key,
10231028
required List<DropdownItem<T>>? items,
1024-
DropdownButtonBuilder? selectedItemBuilder,
1029+
DropdownButton2Builder? selectedItemBuilder,
10251030
ValueListenable<T?>? valueListenable,
1026-
ValueListenable<List<T>>? multiValueListenable,
1031+
ValueListenable<Iterable<T>>? multiValueListenable,
10271032
Widget? hint,
10281033
Widget? disabledHint,
10291034
this.onChanged,

packages/dropdown_button2/lib/src/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ part of 'dropdown_button2.dart';
33
void _uniqueValueAssert<T>(
44
List<DropdownItem<T>>? items,
55
ValueListenable<T?>? valueListenable,
6-
ValueListenable<List<T>>? multiValueListenable,
6+
ValueListenable<Iterable<T>>? multiValueListenable,
77
) {
88
if (items == null || items.isEmpty) {
99
return;

0 commit comments

Comments
 (0)