TreeSliver<T> class

A widget that displays TreeSliverNodes that expand and collapse in a vertically and horizontally scrolling Viewport.

The type T correlates to the type of TreeSliver and TreeSliverNode, representing the type of TreeSliverNode.content.

The rows of the tree are laid out on demand by the Viewport's render object, using TreeSliver.treeNodeBuilder. This will only be called for the nodes that are visible, or within the Viewport.cacheExtent.

The TreeSliver.treeNodeBuilder returns the Widget that represents the given TreeSliverNode.

The TreeSliver.treeRowExtentBuilder returns a double representing the extent of a given node in the main axis.

Providing a TreeSliverController will enable querying and controlling the state of nodes in the tree.

A TreeSliver only supports a vertical axis direction of AxisDirection.down and a horizontal axis direction of AxisDirection.right.

This example uses a TreeSliver to display nodes, highlighting nodes as they are selected.
link

To create a local project with this code sample, run:
flutter create --sample=widgets.TreeSliver.1 mysample

This example shows a highly customized TreeSliver configured to TreeSliverIndentationType.none. This allows the indentation to be handled by the developer in TreeSliver.treeNodeBuilder, where a decoration is used to fill the indented space.
link

To create a local project with this code sample, run:
flutter create --sample=widgets.TreeSliver.2 mysample

Inheritance

Constructors

TreeSliver({Key? key, required List<TreeSliverNode<T>> tree, TreeSliverNodeBuilder treeNodeBuilder = TreeSliver.defaultTreeNodeBuilder, TreeSliverRowExtentBuilder treeRowExtentBuilder = TreeSliver.defaultTreeRowExtentBuilder, TreeSliverController? controller, TreeSliverNodeCallback? onNodeToggle, AnimationStyle? toggleAnimationStyle, TreeSliverIndentationType indentation = TreeSliverIndentationType.standard, bool addAutomaticKeepAlives = true, bool addRepaintBoundaries = true, bool addSemanticIndexes = true, SemanticIndexCallback semanticIndexCallback = _kDefaultSemanticIndexCallback, int semanticIndexOffset = 0, int? findChildIndexCallback(Key)?})
Creates an instance of a TreeSliver for displaying TreeSliverNodes that animate expanding and collapsing of nodes.
const

Properties

addAutomaticKeepAlives bool
Whether to wrap each child in an AutomaticKeepAlive.
final
addRepaintBoundaries bool
Whether to wrap each child in a RepaintBoundary.
final
addSemanticIndexes bool
Whether to wrap each child in an IndexedSemantics.
final
controller TreeSliverController?
If provided, the controller can be used to expand and collapse TreeSliverNodes, or lookup information about the current state of the TreeSliver.
final
findChildIndexCallback → (int? Function(Key)?)
Called to find the new index of a child based on its key in case of reordering.
final
hashCode int
The hash code for this object.
no setterinherited
indentation TreeSliverIndentationType
The number of pixels children will be offset by in the cross axis based on their TreeSliverNode.depth.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onNodeToggle TreeSliverNodeCallback?
Called when a TreeSliverNode expands or collapses.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
semanticIndexCallback SemanticIndexCallback
A SemanticIndexCallback which is used when addSemanticIndexes is true.
final
semanticIndexOffset int
An initial offset to add to the semantic indexes generated by this widget.
final
toggleAnimationStyle AnimationStyle?
The default AnimationStyle for expanding and collapsing nodes in the TreeSliver.
final
tree List<TreeSliverNode<T>>
The list of TreeSliverNodes that may be displayed in the TreeSliver.
final
treeNodeBuilder TreeSliverNodeBuilder
Called to build and entry of the TreeSliver for the given node.
final
treeRowExtentBuilder TreeSliverRowExtentBuilder
Called to calculate the extent of the widget built for the given TreeSliverNode.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<TreeSliver<T>>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

defaultToggleAnimationStyle AnimationStyle
The default AnimationStyle used for node expand and collapse animations, when one has not been provided in toggleAnimationStyle.
getter/setter pair

Static Methods

defaultTreeNodeBuilder(BuildContext context, TreeSliverNode<Object?> node, AnimationStyle toggleAnimationStyle) Widget
Returns the default tree row for a given TreeSliverNode.
defaultTreeRowExtentBuilder(TreeSliverNode<Object?> node, SliverLayoutDimensions dimensions) double
Returns the fixed default extent for rows in the tree, which is 40 pixels.
wrapChildToToggleNode({required TreeSliverNode<Object?> node, required Widget child}) Widget
A wrapper method for triggering the expansion or collapse of a TreeSliverNode.

Constants

defaultAnimationCurve → const Curve
A default of Curves.linear, which is used in the tree's expanding and collapsing node animation.
defaultAnimationDuration → const Duration
A default Duration of 150 milliseconds, which is used in the tree's expanding and collapsing node animation.