Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate TreeViewItems From data #729

Closed
hugetiny opened this issue Feb 8, 2023 · 3 comments
Closed

Generate TreeViewItems From data #729

hugetiny opened this issue Feb 8, 2023 · 3 comments

Comments

@hugetiny
Copy link

hugetiny commented Feb 8, 2023

Is your feature request related to a problem? Please describe.
I tried adding directory tree like data (Infinite nesting maybe) to nested TreeViewItems ,but don't know how.
Flutter does not contain a 'id' or 'class' property and ‘queryselector’ like method to find the specific widget .So I can't continuously add children in TreeViewItem with directory tree like data

Describe the solution you'd like
Make flat data format or tree like data format to treeViewItems.
data format like this

List flat = [{id: 0, type: folder, name: home, parentId: -1, children: [1, 2, 3, 7]}, {id: 1, type: file, name: fuck1, parentId: 0}, {id: 2, type: file, name: fuck2, parentId: 0}, {id: 3, type: folder, name: 0000, parentId: 0, children: [4, 5]}, {id: 4, type: file, name: fuck3, parentId: 3}, {id: 5, type: folder, name: ODLC, parentId: 3, children: [6]}, {id: 6, type: file, name: fuck4, parentId: 5}, {id: 7, type: folder, name: ODLC, parentId: 0, children: [8]}, {id: 8, type: folder, name: 0000, parentId: 7, children: [9]}, {id: 9, type: file, name: fuck5, parentId: 8}]

the method should like

TreeViewItems.fromData(List flat)

Describe alternatives you've considered
Is buildContext.element.visitAncestorElements method a solution for Infinite nesting data to TreeViewItems ?

@bdlukaa
Copy link
Owner

bdlukaa commented Feb 9, 2023

Hello!

¹ Maybe Iterable.map method is the way to go? Something like the following:

final items = data.map<TreeViewItem>((e) {
  return TreeViewItem(
    ...,
  );
}).toList();

² You can also try lazy loading items using the lazy property

Flutter does not contain a 'id' or 'class' property and ‘queryselector’ like method to find the specific widget .

you can make use of keys as the id for the item.


If the above can not help, could you explain in detail the issue?

@hugetiny
Copy link
Author

hugetiny commented Feb 9, 2023

The Widget structure of "items" in TreeView is nested while the data structure is plain.So map method is not the way to go .
This is a directory tree data .So TreeViewSelectionMode.multiple is necessary and I have to load all the data together ,lazy loading is not a way either.

So which method can i find a specific widget with a key?

@hugetiny
Copy link
Author

hugetiny commented Feb 9, 2023

solved

@hugetiny hugetiny closed this as completed Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants