Skip to content

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

Closed
flutter/packages
#6864

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.

Activity

  1. added
    in triagePresently being triaged by the triage team
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: scrollingViewports, list views, slivers, etc.
    packageflutter/packages repository. See also p: labels.
    c: proposalA detailed proposal for a change to Flutter
    p: two_dimensional_scrollablesIssues pertaining to the two_dimensional_scrollables package
    and removed
    in triagePresently being triaged by the triage team
    on Jun 5, 2024
  2. added
    r: fixedIssue is closed as already fixed in a newer version
    on Jun 7, 2024
  3. github-actions commented on Jun 21, 2024

    @github-actions

    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 -v and a minimal reproduction of the issue.

  4. locked as resolved and limited conversation to collaborators on Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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