flutter_tree_view icon indicating copy to clipboard operation
flutter_tree_view copied to clipboard

Both horizontal and vertical scroll?

Open user97116 opened this issue 1 year ago • 10 comments

I used and not work in CustomScroll, CustomScroll, SingleChildScrollView any solution?

user97116 avatar May 21 '23 11:05 user97116

Waiting on https://flutter.dev/go/2D-Foundation

baumths avatar May 21 '23 11:05 baumths

This is a feature I really want

image

Hilbert2048 avatar May 26 '23 15:05 Hilbert2048

@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 avatar Aug 17 '23 00:08 julek-kal

@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 avatar Sep 06 '23 21:09 igormidev

@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🙂

julek-kal avatar Sep 08 '23 00:09 julek-kal

is there any alternative while waiting for this?

stephane-archer avatar Sep 19 '23 15:09 stephane-archer

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.

baumths avatar Sep 30 '23 22:09 baumths

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 avatar Sep 30 '23 22:09 baumths

@baumths I dont get the horizontal scroll to work, did you do something else?

DirtyNative avatar Dec 04 '23 12:12 DirtyNative

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: ...,
                ),
              ),
            ),
          );
        },
      ),
    );
  }

rubenlop88 avatar May 05 '24 16:05 rubenlop88