Home > Back-end >  How use onTap function of treeview library flutter
How use onTap function of treeview library flutter

Time:12-05

Hi I am using this pubdev package 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??

CodePudding user response:

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;
});
  • Related