forceRecursiveList function
- dynamic item
Ensure the given item
is a List.
If item
is null
, an empty list is returned.
If item
is already a Iterable, a copy of items is returned in list.
If any item in the item
is an Iterable, it is expanded into the list recursively.
Otherwise, item
is wrapped in a list and returned.
Implementation
List<dynamic> forceRecursiveList(dynamic item) {
var list = <dynamic>[];
if (item != null) {
if (item is Iterable) {
for (var e in item) {
list.addAll(forceRecursiveList(e));
}
return list;
} else {
list.add(item);
}
}
return list;
}