notifyNodeInserting method
- T newSubTree,
- T parentNode,
- int position,
- void insertFn(
- {int index,
- AnimatedListController controller}
This method has to be called when a new subtree newSubTree
is about to be inserted
as child of the parentNode
at the position position
.
Pass your function to insertFn
that takes care of actually inserting the node.
If you also have the parent's index of the corresponding list view item, that's better
pass it through the index
attribute, otherwise you can just omit it.
If you pass a controller
, the linked animated list view will be automatically notified.
If you don't pass a controller
, a Range will be returned to indicate
the range of items of the list view involved in the modification.
Implementation
Range notifyNodeInserting(
T newSubTree, T parentNode, int position, void Function() insertFn,
{int index, AnimatedListController controller}) {
if (!isNodeExpanded(parentNode)) {
insertFn.call();
return null;
}
index = _ensureIndex(parentNode, index);
assert(newSubTree != null && position != null);
assert(position >= 0 && position <= childrenCount(parentNode));
var from = index + (includeRoot ? 0 : 1); // first child index
for (var i = 0; i < position; i++) {
from += countSubTree(childAt(parentNode, i));
}
final to = from + countSubTree(newSubTree);
return _notify(from, to, parentNode, insertFn, index, controller, _insert,
(from, count) {
controller.notifyInsertedRange(from, count);
});
}