Skip to content

TreeSliver first node visual bug while collapsing/expanding #188305

Closed

Description

@Shunt22

Steps to reproduce

  1. Run the following code
  2. Expand/collapse First node
  3. Expand/collapse Second node

Expected results

Expanding/Collapsing animation and style are consistent and clear for every node

Actual results

For First node children are rendering above node while expanding/collapsing. See attached video.

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',
      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>(
      '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'),
      ],
    ),
   
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('TreeSliver Demo')),
      body: CustomScrollView(
        slivers: <Widget>[
          TreeSliver<String>(
           toggleAnimationStyle: AnimationStyle(
              duration: Duration(seconds: 1),
              reverseDuration: Duration(seconds: 1),
            ),
            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
Screen_Recording_20260622_145847.mp4

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[Paste your output here]

Activity

  1. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: scrollingViewports, list views, slivers, etc.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    on Jun 22, 2026
  2. mbcorona commented on Jun 22, 2026

    @mbcorona
    Member

    Thanks for the clear repro and video. Routing to the framework team for further investigation

  3. Shunt22 commented on Jun 23, 2026

    @Shunt22
    Author

    I've made some investigation. Looks like this issue is in this line.
    https://github.com/flutter/flutter/blob/stable/packages/flutter/lib/src/rendering/sliver_tree.dart#L375

    Not sure yet why there is a check for parentIndex == 0. Removing this check fixes the issue.

  4. jordancarson1231-arch commented on Jun 23, 2026

    @jordancarson1231-arch
  5. added
    P2Important issues not at the top of the work list
    on Jun 23, 2026
  6. self-assigned this
    on Jun 26, 2026
  7. github-actions commented on Aug 12, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  8. locked as resolved and limited conversation to collaborators on Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listf: scrollingViewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-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