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

Strange behavior when updating tree using asynchronous data #11

Closed
lvyandev opened this issue Jun 3, 2021 · 6 comments · Fixed by #12
Closed

Strange behavior when updating tree using asynchronous data #11

lvyandev opened this issue Jun 3, 2021 · 6 comments · Fixed by #12

Comments

@lvyandev
Copy link

lvyandev commented Jun 3, 2021

In some situations, we need to fetch tree children from server before expand.

late final _dynamicController = TreeViewController(
    onAboutToExpand: (TreeNode nodeAboutToExpand) async {
      if (treeController != _dynamicController) return;

      // add this line
      await Future.delayed(const Duration(milliseconds: 300));

      final children = _dynamicChildrenMap[nodeAboutToExpand.id];

      if (children != null) {
        nodeAboutToExpand.addChildren(
          children.map((child) => TreeNode(id: child, label: child)),
        );
      }
    },
    rootNode: TreeNode(id: 'Root')
      //? Initial Dynamic Nodes
      ..addChild(TreeNode(id: 'A', label: 'A'))
      ..addChild(TreeNode(id: 'B', label: 'B'))
      ..addChild(TreeNode(id: 'C', label: 'C')),
  );

Then it behave like this, I need to retap the expander to let the tree update.

SM-G9550_20210603173513.mp4

Am I using it wrong way? How should I update the treeView after load data async.

@baumths
Copy link
Owner

baumths commented Jun 3, 2021

Hey!

I didn't plan onAboutToExpand to be a future...
So expandNode doesn't await on it.

onAboutToExpand should be syncronous for now.

I'm currently working on a refreshNode feature that's almost done, I just have to run some more tests on it.

Edit: the async part of the package is probably the next feature I'll be working on when I have some spare time.

@lvyandev
Copy link
Author

lvyandev commented Jun 3, 2021

So refreshNode should be a function that can update a specific node on the tree?

@baumths
Copy link
Owner

baumths commented Jun 3, 2021

Yes, and the entire subtree of that node with an option to keep the expanded nodes.

@lvyandev
Copy link
Author

lvyandev commented Jun 3, 2021

With that should be enough for now.
Hope to see it soon

@baumths
Copy link
Owner

baumths commented Jun 3, 2021

And probably with refreshNode we wouldn't need onAboutToExpand anymore because we could do children fetching from NodeWidget asynchronously showing a progress indicator and when that's done, call refreshNode and be all good.

@lvyandev
Copy link
Author

lvyandev commented Jun 3, 2021

I agree with that. Since onAboutToExpand doesn't support async.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants