-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Use case
Add the missing generics to the callbacks and builders of the TreeView widget so users don't have to cast the TreeViewNode's content type in each callback for each node.
This request is based on the accepted feedback to the 1D TreeSliver PR #147171. See #147171 (review).
Current behavior:
TreeView<MyContent>(
tree: myTree,
treeNodeBuilder: (BuildContext context, TreeViewNode<Object?> node, _) {
return MyTreeViewNodeTile(
// Casting as I need to access some state of MyContent deeper down in the widget tree
content: node.content as MyContent,
},
);Changing TreeViewNode<Object?> node to TreeViewNode<MyContent> node shows the following error message:
The argument type 'MyTreeViewNodeTile Function(BuildContext, TreeViewNode<MyContent>, AnimationStyle)' can't be assigned to the parameter type 'Widget Function(BuildContext, TreeViewNode<Object?>, AnimationStyle)'.
Desired behavior:
TreeView<MyContent>(
tree: myTree,
treeNodeBuilder: (BuildContext context, TreeViewNode<MyContent> node, _) {
return MyTreeViewNodeTile(
content: node.content, // No casting needed
},
);The above should apply to all callbacks and builders that receive an instance of TreeViewNode.
Proposal
Add generics to all callbacks and builders of TreeView that are given an instance of TreeViewNode.