Skip to content

[two_dimensional_scrollables] Add generics to the callbacks and builders of TreeView #149656

@baumths

Description

@baumths

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: proposalA detailed proposal for a change to Flutterf: scrollingViewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.p: two_dimensional_scrollablesIssues pertaining to the two_dimensional_scrollables packagepackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework teamwaiting for PR to land (fixed)A fix is in flight

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions