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

Custom name for node #4

Closed Salman3sh closed 1 year ago

Salman3sh commented 1 year ago

Hi,

Currently when adding a new child or node, it is adding a name based on level and key.

What about adding a custom name? Is there any sample for this matter. I am trying to open a dialog to read the name and then I changed the code, but I am receiving some errors.

jawwad-hassan89 commented 1 year ago

HI Salman, I have added an example for using a custom object with TreeNode here

Basically, you will need to wrap the the CustomClass in TreeNode like TreeNode<CustomClass>, and use one of the typed constructors e.g.TreeView.simpleTyped<CustomClass, TreeNode<CustomClass>> instead of the simple constructors, as this allows the linter to correctly identify the class type in the builder.

Now you can access your object in the builder like this: builder: (context, level, item) => item.someFieldInCustomClass