flutter_tree_view
flutter_tree_view copied to clipboard
Both horizontal and vertical scroll?
I used and not work in CustomScroll, CustomScroll, SingleChildScrollView any solution?
Waiting on https://flutter.dev/go/2D-Foundation
This is a feature I really want
@baumths fyi - since flutter 3.13 is live I think that 2D scrolling is ready to use. https://medium.com/flutter/whats-new-in-flutter-3-13-479d9b11df4d
@julek-kal
Are you sure Flutter 3.13 have everything it takes to implement 2D scrolling in this package? They will still add several things about 2d scroll in flutter... 3.13 is just the start
@igormidev No, I'm not sure. That was just info for the author, cause he mentioned that we need to wait for 2D foundation. Since 3.13 has it, I decided to kindly let him know🙂
is there any alternative while waiting for this?
I'm afraid I won't be able to add horizontal scroll support to the tree view widgets.
I've played around with the new 2D scrolling API and found out I won't be able to put in the time needed to develop this feature due to its complexity.
is there any alternative while waiting for this?
The "ugly" way of doing it currently is to set a fixed width to your TreeView:
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: SizedBox(
// width: <some-fixed-number>,
width: MediaQuery.sizeOf(context).width * 2,
child: TreeView(
...
),
),
);
}
@baumths I dont get the horizontal scroll to work, did you do something else?
is there any alternative while waiting for this?
The "ugly" way of doing it currently is to set a fixed width to your TreeView:
@override Widget build(BuildContext context) { return SingleChildScrollView( scrollDirection: Axis.horizontal, child: SizedBox( // width: <some-fixed-number>, width: MediaQuery.sizeOf(context).width * 2, child: TreeView( ... ), ), ); }
Thanks. This works just fine.
I calculate the width like this:
class Node {
...
int get maxDepth {
if (isEmpty) {
return 0;
}
return 1 + _children.map((child) => child.maxDepth).reduce(math.max);
}
}
@override
Widget build(BuildContext context) {
final itemWidth = 300.0;
return DefaultIndentGuide(
guide: const ConnectingLinesGuide(),
child: Builder(
builder: (context) {
final depth = root.maxDepth;
final indent = DefaultIndentGuide.of(context).indent;
final treeWidth = itemWidth + depth * indent;
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Container(
width: treeWidth,
child: AnimatedTreeView<Node>(
...
nodeBuilder: (context, entry) => SizedBox(
width: itemWidth,
child: ...,
),
),
),
);
},
),
);
}