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
Expand All or scroll to node? #30
Comments
Hey @jaxnz, thank your for using the package! To expand all nodes you can use [TreeViewController.expandAll]. Scrolling to a node is not supported currently, but you could implement it yourself by passing a ScrollController to the treeview and calculating the offset to scroll to using the height and index of a node. |
Thanks, was able to do it like this for anyone else that may be wondering:
|
@baumths If we did want to implement our own scroll to node, is there a way to get the height of each of the currently visible tree nodes? |
Hey @mstich-mcmservices, thank you for using this package! Checkout this article from the gskinner team about measuring a widget's size: Using the RenderBox approach: class MeasureSizeRenderObject extends RenderProxyBox {
MeasureSizeRenderObject(this.onChange);
void Function(Size size) onChange;
Size? _prevSize;
@override
void performLayout() {
super.performLayout();
Size newSize = child!.size;
if (_prevSize == newSize) return;
_prevSize = newSize;
WidgetsBinding.instance.addPostFrameCallback((_) => onChange(newSize));
}
}
class MeasurableWidget extends SingleChildRenderObjectWidget {
const MeasurableWidget({
super.key,
required this.onChange,
required this.onUnmount,
required super.child,
});
final ValueChanged<Size> onChange;
final VoidCallback onUnmount;
@override
RenderObject createRenderObject(BuildContext context) {
return MeasureSizeRenderObject(onChange);
}
@override
void didUnmountRenderObject(covariant MeasureSizeRenderObject renderObject) {
super.didUnmountRenderObject(renderObject);
onUnmount();
}
} Usage example: // On the StatefulWidget that builds your TreeView
final Map<Object, Size> nodeToSize = {};
Widget nodebuilder(BuildContext context, TreeEntry<Object> entry) {
return MeasurableWidget(
onChange: (Size size) {
nodeToSize[entry.node] = size;
},
onUnmount: () {
nodeToSize.remove(entry.node);
},
child: YourNodeTile(entry: entry),
);
} After the first frame, |
@baumths Thanks for the example code! I will give it a try and see how it works. I started working with your tree package prior to the big 1.x.x rewrite and I'm now in the process of refactoring to handle moving to 1.4.0. Thank you for your great contribution to the flutter community! |
Is it possible to expand all nodes, or scroll to one?
It looks like #7 has been implemented, but can't figure out how it works.
The text was updated successfully, but these errors were encountered: