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

Unhandled Exception: Exception: Animated list state not found from GlobalKey<AnimatedListState> #12

Open
allanfann opened this issue Mar 23, 2023 · 6 comments

Comments

@allanfann
Copy link

My code:

for (var element in _rootNode.childrenAsList) { if (element.key == parentKey.toString()) { try { element .add(TreeNode(key: context.uid.toString())); } catch (e) {} return; } }

Exception:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Animated list state not found from GlobalKey
#0 _AnimatedListState.insertItem
tree_view.dart:495
#1 AnimatedListController.insert
animated_list_controller.dart:65
#2 AnimatedListController.insertAll
animated_list_controller.dart:70
#3 AnimatedListController.expandNode
animated_list_controller.dart:116
#4 AnimatedListController.handleAddItemsEvent
animated_list_controller.dart:208
#5 _RootZone.runUnaryGuarded (dart:async/zone.dart:1593:10)
#6 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#7 _DelayedData.perform (dart:async/stream_impl.dart:515:14)

@jawwad-hassan89
Copy link
Collaborator

Hi Alan, this issue has been resolved in the release 2.1.0.
It can occur the treeview is updated before it is properly initialized. onTreeReady callback has been specifically added to address this issue. This issue will not occur when any changes are made to the tree after the onTreeReady callback is invoked.

@jitender-kumar-dev
Copy link

@allanfann Are u able to overcome from this issue?
I am seeing this with v2.2.1 also. Here is the link for the issue #53

@bughoho
Copy link

bughoho commented Aug 28, 2024

Hi Alan, this issue has been resolved in the release 2.1.0. It can occur the treeview is updated before it is properly initialized. onTreeReady callback has been specifically added to address this issue. This issue will not occur when any changes are made to the tree after the onTreeReady callback is invoked.

hi,@jawwad-hassan89,I had the same issue, I used the latest 2.2.1, I only had 6 nodes, but I also got this error, and this is my code:

return allLocationNode.widgetWhen(
        onData: (node) {
          return Container(
            color: Theme.of(context).scaffoldBackgroundColor,
            child: TreeView.simple(
              padding: const EdgeInsets.all(0),
              showRootNode: false,
              shrinkWrap: true,
              tree: node,
              expansionBehavior: ExpansionBehavior.none,
              expansionIndicatorBuilder: (context, node) =>
                  noExpansionIndicatorBuilder(context, node),
              indentation:
                  const Indentation(style: IndentStyle.none, width: 12),
              builder: (context, node) => CupertinoListTile(
                leading: Icon(
                  CupertinoIcons.map_pin,
                  color: context.isDarkTheme ? Colors.white : Colors.black54,
                ),
                onTap: () {
                },
                title: Text(
                  node.key,
                  style: context.textTheme.bodyMedium!,
                ),
              ),
              onTreeReady: (controller) {
                controller.expandAllChildren(node);
              },
            ),
          );
        },
      );

and this is error stack:

Exception: Animated list state not found from GlobalKey<AnimatedListState>

When the exception was thrown, this was the stack:
#0      TreeViewState.insertItem (package:animated_tree_view/tree_view/tree_view.dart:650:40)
tree_view.dart:650
#1      AnimatedListStateController.insert (package:animated_tree_view/tree_view/tree_view_state_helper.dart:187:16)
tree_view_state_helper.dart:187
#2      AnimatedListStateController.insertAll (package:animated_tree_view/tree_view/tree_view_state_helper.dart:192:7)
tree_view_state_helper.dart:192
#3      TreeViewExpansionBehaviourController.expandNode (package:animated_tree_view/tree_view/tree_view_state_helper.dart:253:33)
tree_view_state_helper.dart:253
#4      TreeViewController.expandNode (package:animated_tree_view/tree_view/tree_view.dart:87:60)
tree_view.dart:87
#5      TreeViewController.expandAllChildren (package:animated_tree_view/tree_view/tree_view.dart:100:7)
tree_view.dart:100
#6      MyTestPage.build.buildTestListTile.<anonymous closure>.<anonymous closure> (package:testproject/pages/my_test.page.dart:56:28)
my_test.page.dart:509
#7      _TreeViewState.initState.<anonymous closure> (package:animated_tree_view/tree_view/tree_view.dart:244:27)
tree_view.dart:244
#8      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1397:15)
binding.dart:1397
#9      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1331:11)
binding.dart:1331
#10     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1176:5)
binding.dart:1176
#11     _invoke (dart:ui/hooks.dart:312:13)
hooks.dart:312
#12     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5)
platform_dispatcher.dart:419
#13     _drawFrame (dart:ui/hooks.dart:283:31)
hooks.dart:283

@bughoho
Copy link

bughoho commented Aug 28, 2024

class TreeViewState<Data, Tree extends ITreeNode<Data>>
    extends State<TreeView<Data, Tree>>
    with _TreeViewState<Data, Tree, TreeView<Data, Tree>> {
  static const _errorMsg =
      "Animated list state not found from GlobalKey<AnimatedListState>";

  late final GlobalKey<AnimatedListState> _listKey = GlobalKey<AnimatedListState>();

I finally solved the problem by removing the late keyword, but I don't know if that's the right way to do it:

 final GlobalKey<AnimatedListState> _listKey = GlobalKey<AnimatedListState>();

But I've only solved half of the problem, there's still something wrong with the UI, my TreeView is placed on the second page of a PageView, and the onTreeReady callback function is executed for the first time
controller.expandAllChildren(node)
everything works fine, but the second time I opened the page, it went into a collapse state,expandAllChildren function doesn't work at all

@bughoho
Copy link

bughoho commented Aug 28, 2024

2024-08-29.03.11.38.mov

@jawwad-hassan89
Copy link
Collaborator

Hi @bughoho, will try to reproduce this issue and update you.

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

No branches or pull requests

4 participants