TreeListAdapter<T> constructor

TreeListAdapter<T>(
  1. {@required T root,
  2. @required T parentOf(
    1. T node
    ),
  3. @required int childrenCount(
    1. T node
    ),
  4. @required T childAt(
    1. T node,
    2. int index
    ),
  5. @required bool isNodeExpanded(
    1. T node
    ),
  6. @required int indexOfChild(
    1. T parent,
    2. T node
    ),
  7. bool equals(
    1. T nodeA,
    2. T nodeB
    ): _kEquals,
  8. bool includeRoot: true,
  9. int windowSize: _kWindowSize,
  10. int initialCount,
  11. int startingLevel: 0}
)

Creates a new tree adapter. A root node has to be specified.

The model consists of following callbacks:

  • parentOf returns the parent node of a node;
  • childrenCount returns the number of the children of a node;
  • childAt returns the child node of a parent node at a specific position;
  • isNodeExpanded returns true if the node is expanded, false if it is collapsed;
  • indexOfChild returns the position of a child node;
  • equals returns true if two nodes are equals; if this callback is omitted, the == operator will be used;

If includeRoot is set to true, the list view will also show the root node as the first item.

You can specify by windowSize the size of the circular list used to cache the items.

You can also pass by initialCount the initial count of all tree nodes if it is known, to prevent the full scan of the tree in order to calculate its size.

Implementation

TreeListAdapter({
  @required this.root,
  @required this.parentOf,
  @required this.childrenCount,
  @required this.childAt,
  @required this.isNodeExpanded,
  @required this.indexOfChild,
  this.equals = _kEquals,
  this.includeRoot = true,
  this.windowSize = _kWindowSize,
  int initialCount,
  this.startingLevel = 0,
})  : assert(root != null),
      assert(parentOf != null),
      assert(childrenCount != null),
      assert(childAt != null),
      assert(isNodeExpanded != null),
      assert(indexOfChild != null),
      assert(equals != null),
      assert(includeRoot != null),
      assert(windowSize != null),
      assert(startingLevel != null),
      _list = CircularList(windowSize) {
  if (initialCount != null) {
    assert(initialCount == count);
    _count = initialCount;
  }
}