Skip to content

Commit 86a6fca

Browse files
committed
Fix dropdown crashing on list having duplicate items.
1 parent 9430734 commit 86a6fca

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/src/transformers/node_transformers/passive_dropdown_transformer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class PassiveDropdownWidget extends StatelessWidget {
189189
splashColor: node.properties.splashColor?.toFlutterColor(),
190190
),
191191
child: DropdownButton<Object>(
192-
value: items.isEmpty || !items.contains(value) ? null : value,
192+
value: items.isEmpty || items.count(value) != 1 ? null : value,
193193
isDense: node.properties.dense,
194194
isExpanded: node.properties.expanded,
195195
autofocus: node.properties.autoFocus,

lib/src/utils/extensions.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,8 @@ extension IterableExt<V> on Iterable<V> {
18311831
Map<K, V> mapBy<K>(K Function(V) key) => <K, V>{
18321832
for (final value in this) key(value): value,
18331833
};
1834+
1835+
int count(V item) => where((e) => e == item).length;
18341836
}
18351837

18361838
extension TabBarIndicatorSizeExtensions on TabBarIndicatorSizeEnum {

0 commit comments

Comments
 (0)