embraceitmobile / animated_tree_view

Animated TreeView based on AnimatedList allows building fully customizable Nodes that can be nested to infinite levels and children.
https://pub.dev/packages/animated_tree_view
MIT License
49 stars 23 forks source link

Question: Is there a way to deactivate "toggleExpansion" ? #20

Open DasTobbel opened 1 year ago

DasTobbel commented 1 year ago

Hi, i'm looking for a way to, based on the item, to deactivate the expansion/collapse of its children. Is there a way currently ?

Or is it something you want to achieve? If yes, my suggestion would be something like, i could do the PR:

  Future<void> toggleExpansion(ITreeNode<Data> item) async {
    if (item.isExpandable == false) {
      return;
    }
    if (item.isExpanded)
      await collapseNode(item);
    else {
      expandNode(item);
      await applyExpansionBehavior(item);
    }
  }

Greets!

jawwad-hassan89 commented 1 year ago

Logically speaking, if a node has children then it should be expandable, otherwise, it shouldn't have any children. So, I would rather not have this functionality, but you are free to create your own fork for this change set.

DasTobbel commented 12 months ago

Ah, let me rephrase it: I want to forbid the collapsing of node+children as i click on the node.

Currently if i use the treeview and the node has children, the "onItemTap" function will collapse/expand the clicked node while executing the "onItemTap" function.

Probably something like this, while adding the default "node.mayCollapse = true"?

  Future<void> toggleExpansion(ITreeNode<Data> item) async {
   if (item.isExpanded && item.children.isNotEmpty && item.mayCollapse == false) {
      return;
    }
    else if (item.isExpanded &&  item.mayCollapse)
      await collapseNode(item);
    else {
      expandNode(item);
      await applyExpansionBehavior(item);
    }
  }