Skip to content

Conversation

samuelsadok
Copy link

In 734a064, generic type support was added, but it appears to be incomplete.

As a result, when running something like this:

myController.withExpandToNode(key).withUpdateNode(
          key,
          myController.getNode(key)!.copyWith(expanded: isExpanded),
        );

it throws _TypeError (type 'List<Node<dynamic>>' is not a subtype of type 'List<Node<NodeData>>?' of 'children').

The error happens on this line in the library:

List<Node<T>> updateNode(String key, Node<T> newNode, {Node<T>? parent}) {
// ...
        if (child.isParent) {
          return child.copyWith(  // <==== on this line
            children: updateNode(
              key,
              newNode,
              parent: child,
            ),
          );
        }
// ...
}

I don't have a comprehensive explanation why this happens. From printing runtimeType in various places and stepping through with the debugger, I'm seeing inconsistent output and it almost looks like a bug in the Dart tooling to me. However it seems to have something to do with withExpandToNode(key) returning a compile-time type of TreeViewController<dynamic>, which then results in conflicting types in the subsequent withUpdateNode(). Making the return type explicit fixes my use case.

Dart 3.7
Flutter 3.29

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 this pull request may close these issues.

1 participant