findRightmostOfABranch<T extends AbsNodeType> function
If we use canvas to draw lines in expandable tree view (look at example), we will wonder, what is the rightmost node in current branch of tree? Because the line in rightmost node has little difference from other.
Notice: Find the rightmost of a BRANCH (current level minus 1), not entire tree.
Implementation
TreeType<T> findRightmostOfABranch<T extends AbsNodeType>(TreeType<T> tree) {
if (tree.data.isInner && tree.children.isEmpty) return tree;
if (tree.isRoot) return findRightmostOfABranch(tree.children.last);
var lastChildOfCurrentParent = tree.parent!.children.last;
if (identical(lastChildOfCurrentParent, tree)) return tree;
return findRightmostOfABranch(lastChildOfCurrentParent);
}