itemFactory method
The single canonical factory for creating a TListItem from raw data.
Accepts optional childrenKeys to override auto-resolution from itemChildren.
When childrenKeys is not provided and itemChildren is set, children are resolved automatically.
Implementation
TListItem<T, K> itemFactory(
T data, {
K? parentKey,
List<K>? childrenKeys,
int level = 0,
}) {
final resolvedChildrenKeys = childrenKeys ??
(() {
final children = itemChildren?.call(data);
return children != null && children.isNotEmpty ? children.map(itemKey).toList() : null;
})();
return TListItem<T, K>(
key: itemKey(data),
data: data,
parentKey: parentKey,
childrenKeys: resolvedChildrenKeys,
level: level,
);
}