How use onTap function of treeview library flutter

Issue

Hi I am using this pubdev package https://pub.dev/packages/tree_view/example . My problem is that when I use the onTap function the expanded does not work, I was checking the library and I noticed that it is because of this code, however I do not know how to solve it or if there is another way to access that function from the library from the widget. Any ideas enter image description here

If you notice it when the onTap function is different from empty, the toggleExpanded() function does not apply
enter image description here

So any ideas??

Solution

You need to control the expansion yourself using the startExpanded property of the TreeView widget.

First, you have a boolean variable (say _startExpanded) in your StatefulWidget that hold the state of the expansion and you can set it the default state (for instance, false).

bool _startExpanded = false;

Then, you pass the variable to your TreeView widget:

TreeView(
    startExpanded: _startExpanded,
    children: _getChildList(documentList),
),

To expand, you call:

setState((){
  _startExpanded = true;
});

To close, you call:

setState((){
  _startExpanded = false;
});

Answered By – Victor Eronmosele

Answer Checked By – Senaida (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.