diff --git a/lib/src/tree_node.dart b/lib/src/tree_node.dart index 2181641..aab0e7a 100644 --- a/lib/src/tree_node.dart +++ b/lib/src/tree_node.dart @@ -109,6 +109,14 @@ class _TreeNodeState extends State> } } + void _handleLongPress() { + TreeView? _treeView = TreeView.of(context); + assert(_treeView != null, 'TreeView must exist in context'); + if (_treeView!.onNodeLongPress != null) { + _treeView.onNodeLongPress!(widget.node.key); + } + } + void _handleDoubleTap() { TreeView? _treeView = TreeView.of(context); assert(_treeView != null, 'TreeView must exist in context'); @@ -213,17 +221,20 @@ class _TreeNodeState extends State> Widget _tappable = _treeView.onNodeDoubleTap != null ? InkWell( onTap: _handleTap, + onLongPress: _handleLongPress, onDoubleTap: _handleDoubleTap, child: labelContainer, ) : InkWell( onTap: _handleTap, + onLongPress: _handleLongPress, child: labelContainer, ); if (widget.node.isParent) { if (_treeView.supportParentDoubleTap && canSelectParent) { _tappable = InkWell( onTap: canSelectParent ? _handleTap : _handleExpand, + onLongPress: _handleLongPress, onDoubleTap: () { _handleExpand(); _handleDoubleTap(); @@ -233,12 +244,14 @@ class _TreeNodeState extends State> } else if (_treeView.supportParentDoubleTap) { _tappable = InkWell( onTap: _handleExpand, + onLongPress: _handleLongPress, onDoubleTap: _handleDoubleTap, child: labelContainer, ); } else { _tappable = InkWell( onTap: canSelectParent ? _handleTap : _handleExpand, + onLongPress: _handleLongPress, child: labelContainer, ); } diff --git a/lib/src/tree_view.dart b/lib/src/tree_view.dart index 057bc1d..8251b15 100644 --- a/lib/src/tree_view.dart +++ b/lib/src/tree_view.dart @@ -38,6 +38,9 @@ class TreeView extends InheritedWidget { /// The double tap handler for a node. Passes the node key. final Function(String)? onNodeDoubleTap; + /// The long press handler for a node. Passes the node key. + final Function(String)? onNodeLongPress; + /// The expand/collapse handler for a node. Passes the node key and the /// expansion state. final Function(String, bool)? onExpansionChanged; @@ -81,6 +84,7 @@ class TreeView extends InheritedWidget { required this.controller, this.onNodeTap, this.onNodeDoubleTap, + this.onNodeLongPress, this.physics, this.onExpansionChanged, this.allowParentSelect: false, @@ -107,6 +111,7 @@ class TreeView extends InheritedWidget { bool updateShouldNotify(TreeView oldWidget) { return oldWidget.controller.children != this.controller.children || oldWidget.onNodeTap != this.onNodeTap || + oldWidget.onNodeLongPress != this.onNodeLongPress || oldWidget.onExpansionChanged != this.onExpansionChanged || oldWidget.theme != this.theme || oldWidget.supportParentDoubleTap != this.supportParentDoubleTap ||