Skip to content

TreeSlivers are hidden behind the SliverAppBar in a CustomScrollView #166326

@SeriousMonk

Description

@SeriousMonk

Steps to reproduce

Aadd a SliverAppBar like the following

SliverAppBar(
   expandedHeight: MediaQuery.of(context).size.height * 0.5,
   automaticallyImplyLeading: false,
   flexibleSpace: FlexibleSpaceBar(
     title: Text('BLABLABLABALBLA'),
   ),
),

as first sliver in the CustomScrollView in the example code at https://api.flutter.dev/flutter/widgets/TreeSliver-class.html

Expected results

The TreeSliver be displayed after the end of the SliverAppBar like any other sliver.

Actual results

The TreeSliver is displayed at the beginning of the CustomScrollView and gets covered by the SliverAppBar.

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>[
          SliverAppBar(
          expandedHeight: MediaQuery.of(context).size.height * 0.5,
          automaticallyImplyLeading: false,
          backgroundColor: Colors.red,
          flexibleSpace: FlexibleSpaceBar(
            title: Text('BLABLABLABALBLA'),
          ),
        ),
          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

TreeSliver.class.-.widgets.library.-.Dart.API.-.Google.Chrome.2025-04-01.13-53-17.mp4
Screenshots / Video demonstration

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.29.2, on Microsoft Windows [Version 10.0.22631.5039], locale en-US)
[√] Windows Version (11 Pro 64-bit, 23H2, 2009)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[√] Chrome - develop for the web
[X] Visual Studio - develop Windows apps
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2024.1)
[√] VS Code (version 1.98.2)
[√] Connected device (3 available)
[√] Network resources

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listf: material designflutter/packages/flutter/material repository.found in release: 3.29Found to occur in 3.29found in release: 3.31Found to occur in 3.31frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions