Repository navigation
[two_dimensional_scrollables] Add generics to the callbacks and builders of TreeView #149656
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.
Activity
[two_dimensional_scrollables] Adds generics to the callbacks and buil…
github-actions commentedon Jun 21, 2024
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.[two_dimensional_scrollables] Adds generics to the callbacks and buil…
[two_dimensional_scrollables] Adds generics to the callbacks and buil…