-
Notifications
You must be signed in to change notification settings - Fork 26.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TreeSliver & associated classes #147171
base: master
Are you sure you want to change the base?
TreeSliver & associated classes #147171
Conversation
For tomorrow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for the examples!
Spotted minor typos in the non-examples files.
packages/flutter/lib/src/rendering/sliver_multi_box_adaptor.dart
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello team, please consider adding generics to the callbacks and builders of the TreeSliver
and TreeView
(from two_dimensional_scrollables
) so users can avoid casting the TreeSliverNode.content
in each callback. Example:
TreeSliver<MyItem>(
tree: myTree,
treeNodeBuilder: (BuildContext context, TreeSliverNode<Object?> node, _) {
return MyTreeSliverNodeTile(
// Casting as I need to access some state of MyItem deeper down in the widget tree
item: node.content as MyItem,
},
// In the `TreeView` widget, I'm using this callback to add focus/hover/active decorations to the whole width of a node
treeRowExtentBuilder: (TreeSliverNode<Object?> node, _) {
final item = node.content as MyItem;
return item.preferredHeight;
},
onNodeToggle: (TreeSliverNode<Object?> node) {
final item = node.content as MyItem;
myStorage.persistMyItemExpansionState(item.id, node.isExpanded);
},
);
If I just change the type to TreeSliverNode<MyItem>
I get the following error message:
The argument type 'MyTreeSliverNodeTile Function(BuildContext, TreeSliverNode<MyItem>, AnimationStyle)' can't be assigned to the parameter type 'Widget Function(BuildContext, TreeSliverNode<Object?>, AnimationStyle)'.
/// | ||
/// Used by [TreeSliver.treeNodeBuilder] to build rows on demand for the | ||
/// tree. | ||
typedef TreeSliverNodeBuilder = Widget Function( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typedef TreeSliverNodeBuilder = Widget Function( | |
typedef TreeSliverNodeBuilder<T> = Widget Function( |
/// tree. | ||
typedef TreeSliverNodeBuilder = Widget Function( | ||
BuildContext context, | ||
TreeSliverNode<Object?> node, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TreeSliverNode<Object?> node, | |
TreeSliverNode<T> node, |
/// | ||
/// By default, if this is unset, the [TreeSliver.defaultTreeNodeBuilder] | ||
/// is used. | ||
final TreeSliverNodeBuilder treeNodeBuilder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final TreeSliverNodeBuilder treeNodeBuilder; | |
final TreeSliverNodeBuilder<T> treeNodeBuilder; |
/// | ||
/// * [SliverVariedExtentList], which uses a similar item extent builder for | ||
/// dynamic child sizing in the list. | ||
typedef TreeSliverRowExtentBuilder = double Function( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typedef TreeSliverRowExtentBuilder = double Function( | |
typedef TreeSliverRowExtentBuilder<T> = double Function( |
/// * [SliverVariedExtentList], which uses a similar item extent builder for | ||
/// dynamic child sizing in the list. | ||
typedef TreeSliverRowExtentBuilder = double Function( | ||
TreeSliverNode<Object?> node, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TreeSliverNode<Object?> node, | |
TreeSliverNode<T> node, |
/// | ||
/// * [TreeSliver.onNodeToggle], for controlling node expansion | ||
/// programmatically. | ||
typedef TreeSliverNodeCallback = void Function(TreeSliverNode<Object?> node); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typedef TreeSliverNodeCallback = void Function(TreeSliverNode<Object?> node); | |
typedef TreeSliverNodeCallback<T> = void Function(TreeSliverNode<T> node); |
/// | ||
/// * [SliverVariedExtentList.itemExtentBuilder], a very similar method that | ||
/// allows users to dynamically compute extents on demand. | ||
final TreeSliverRowExtentBuilder treeRowExtentBuilder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final TreeSliverRowExtentBuilder treeRowExtentBuilder; | |
final TreeSliverRowExtentBuilder<T> treeRowExtentBuilder; |
/// Called when a [TreeSliverNode] expands or collapses. | ||
/// | ||
/// This will not be called if a [TreeSliverNode] does not have any children. | ||
final TreeSliverNodeCallback? onNodeToggle; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final TreeSliverNodeCallback? onNodeToggle; | |
final TreeSliverNodeCallback<T>? onNodeToggle; |
FYI for Reviewers: Much of the API surface matches that of the 2D TreeView in flutter/packages#6592. If it changes here, it should change there, and vice versa.
📜 Design Document
This adds classes and associated callbacks and controllers for TreeSliver. Core components:
Fixes #114299
sliver_0.mov
sliver_1.mov
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.