TolyDraggableTree<T> class

基于 TolyTree 的可拖拽树形组件

支持节点拖拽排序和层级调整的树形组件。提供丰富的自定义选项和开箱即用的默认行为。

基本用法

TolyDraggableTree<MyData>(
  nodes: treeNodes,
  nodeBuilder: (node) => Text(node.data.name),
  onNodeMoved: (result) {
    print('${result.dragNode.data.name} moved to ${result.position}');
  },
)

高级用法

TolyDraggableTree<FileItem>(
  nodes: fileNodes,
  nodeBuilder: _buildFileNode,
  canDrop: (dragNode, targetNode, position) {
    // 文件只能放入文件夹
    if (!dragNode.data.isFolder && position == DropPosition.inside) {
      return targetNode?.data.isFolder ?? false;
    }
    return true;
  },
  dragFeedbackBuilder: DragFeedbacks.shadow<FileItem>(_buildFileNode),
  enableBuiltinNodeManagement: true,
  autoExpandOnDrop: true,
)
Inheritance

Constructors

TolyDraggableTree({Key? key, required List<TreeNode<T>> nodes, required Widget nodeBuilder(TreeNode<T>), dynamic onTap(TreeNode<T>)?, dynamic onExpand(TreeNode<T>)?, bool canDrop(TreeNode<T> dragNode, TreeNode<T>? targetNode, DropPosition position)?, void onNodeMoved(DragResult<T> result)?, Widget dragFeedbackBuilder(TreeNode<T> node)?, Widget childWhenDraggingBuilder(TreeNode<T> node)?, bool autoExpandOnDrop = true, bool autoManageNode = true, double indent = 24.0, Widget? expandIcon, Widget? collapseIcon, Duration animationDuration = const Duration(milliseconds: 200), Curve animationCurve = Curves.easeInOut, bool showConnectingLines = false, Color? connectingLineColor, double connectingLineWidth = 1.0})
const

Properties

animationCurve Curve
展开/折叠动画曲线
final
animationDuration Duration
展开/折叠动画时长
final
autoExpandOnDrop bool
是否在拖拽到文件夹内部时自动展开文件夹
final
autoManageNode bool
是否启用内置的节点管理
final
canDrop bool Function(TreeNode<T> dragNode, TreeNode<T>? targetNode, DropPosition position)?
拖拽规则验证函数
final
childWhenDraggingBuilder Widget Function(TreeNode<T> node)?
拖拽时原位置节点的样式构建器
final
collapseIcon Widget?
自定义折叠图标
final
connectingLineColor Color?
连接线颜色
final
connectingLineWidth double
连接线宽度
final
dragFeedbackBuilder Widget Function(TreeNode<T> node)?
拖拽时的反馈样式构建器
final
expandIcon Widget?
自定义展开图标
final
hashCode int
The hash code for this object.
no setterinherited
indent double
子节点缩进距离(像素)
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
nodeBuilder Widget Function(TreeNode<T>)
节点构建器,定义每个节点的显示内容
final
nodes List<TreeNode<T>>
树形数据节点列表
final
onExpand → dynamic Function(TreeNode<T>)?
节点展开/折叠回调
final
onNodeMoved → void Function(DragResult<T> result)?
节点移动完成回调
final
onTap → dynamic Function(TreeNode<T>)?
节点点击回调
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
showConnectingLines bool
是否显示连接线
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<TolyDraggableTree<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, int wrapWidth = 65}) 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