Skip to content

TreeSliver - collapsing not working on web #153418

@arturoszulc

Description

@arturoszulc

Steps to reproduce

  1. Go to https://api.flutter.dev/flutter/widgets/TreeSliver-class.html
  2. Run any of the two examples on the page.
  3. Expand any node and try to collapse it

Collapsing doesn't work neither on online example, nor local web build.

Expected results

Tree node collapses

Actual results

Tree node does not collapse

Code sample

Code sample
import 'package:flutter/material.dart';

/// Flutter code sample for [TreeSliver].

void main() => runApp(const TreeSliverExampleApp());

class TreeSliverExampleApp extends StatelessWidget {
  const TreeSliverExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: TreeSliverExample(),
    );
  }
}

class TreeSliverExample extends StatefulWidget {
  const TreeSliverExample({super.key});

  @override
  State<TreeSliverExample> createState() => _TreeSliverExampleState();
}

class _TreeSliverExampleState extends State<TreeSliverExample> {
  TreeSliverNode<String>? _selectedNode;
  final TreeSliverController controller = TreeSliverController();
  final List<TreeSliverNode<String>> _tree = <TreeSliverNode<String>>[
    TreeSliverNode<String>('First'),
    TreeSliverNode<String>(
      'Second',
      children: <TreeSliverNode<String>>[
        TreeSliverNode<String>(
          'alpha',
          children: <TreeSliverNode<String>>[
            TreeSliverNode<String>('uno'),
            TreeSliverNode<String>('dos'),
            TreeSliverNode<String>('tres'),
          ],
        ),
        TreeSliverNode<String>('beta'),
        TreeSliverNode<String>('kappa'),
      ],
    ),
    TreeSliverNode<String>(
      'Third',
      expanded: true,
      children: <TreeSliverNode<String>>[
        TreeSliverNode<String>('gamma'),
        TreeSliverNode<String>('delta'),
        TreeSliverNode<String>('epsilon'),
      ],
    ),
    TreeSliverNode<String>('Fourth'),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('TreeSliver Demo'),
      ),
      body: CustomScrollView(
        slivers: <Widget>[
          TreeSliver<String>(
            tree: _tree,
            controller: controller,
            treeNodeBuilder: (
              BuildContext context,
              TreeSliverNode<Object?> node,
              AnimationStyle animationStyle,
            ) {
              Widget child = GestureDetector(
                behavior: HitTestBehavior.translucent,
                onTap: () {
                  setState(() {
                    controller.toggleNode(node);
                    _selectedNode = node as TreeSliverNode<String>;
                  });
                },
                child: TreeSliver.defaultTreeNodeBuilder(
                  context,
                  node,
                  animationStyle,
                ),
              );
              if (_selectedNode == node as TreeSliverNode<String>) {
                child = ColoredBox(
                  color: Colors.purple[100]!,
                  child: child,
                );
              }
              return child;
            },
          ),
        ],
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration
slivertree.example.mp4

Logs

No response

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.24.0, on Microsoft Windows [Version 10.0.22631.3880], locale pl-PL)
    • Flutter version 3.24.0 on channel stable at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 80c2e84975 (2 weeks ago), 2024-07-30 23:06:49 +0700
    • Engine revision b8800d88be
    • Dart version 3.5.0
    • DevTools version 2.37.2

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at C:\Users\artur\AppData\Local\Android\Sdk
    • Platform android-33, build-tools 33.0.2
    • ANDROID_HOME = C:\Users\artur\AppData\Local\Android\Sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.1.3)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.1.32328.378
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2022.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)

[√] VS Code, 64-bit edition (version 1.92.0)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.94.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22631.3880]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 127.0.6533.101
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 127.0.2651.98

[√] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listf: scrollingViewports, list views, slivers, etc.found in release: 3.24Found to occur in 3.24frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: two_dimensional_scrollablesIssues pertaining to the two_dimensional_scrollables packageplatform-webWeb applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions