RenderTreeSliver.paint does not subtract constraints.scrollOffset from animating clip rect

Open Beginner friendly
#197,725 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@Ultranmus is already working on this.

Since Dec 2, 2026.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
dart, flutter
Domain
frontend

Research direction

Start in packages/flutter/lib/src/rendering/sliver_tree.dart, where the issue identifies the clip rectangle in RenderTreeSliver.paint and compares it with paintUpTo positioning. Check how the scroll offset is applied to paint coordinates, then reproduce by scrolling to Parent 19 and toggling it. Done when its children animate smoothly beneath the parent while scrolled, matching the behavior at offset zero.

Written by the indexing model from the issue text.

Description

f: scrolling framework has reproducible steps team-framework
Steps to reproduce
  1. Run the code sample below (flutter run).
  2. Scroll to the bottom of the list so Parent 19 is visible (scrollOffset > 0).
  3. Tap Parent 19 to expand or collapse it (the 500ms animation duration makes the clipping easy to observe).
Expected results

Parent 19's children smoothly slide out from directly underneath Parent 19, matching the animation when expanding Parent 0 at scrollOffset == 0.

Actual results

The clip rectangle pushed by RenderTreeSliver.paint (packages/flutter/lib/src/rendering/sliver_tree.dart, lines 379–387) is computed from layout offsets without subtracting constraints.scrollOffset:

final double leadingOffset =
    indexToLayoutOffset(0.0, parentIndex) + itemExtentBuilder(parentIndex, layoutDimensions)!;
final double trailingOffset =
    indexToLayoutOffset(0.0, segment.trailingIndex) +
    itemExtentBuilder(segment.trailingIndex, layoutDimensions)!;
final rect = Rect.fromPoints(
  Offset(0.0, leadingOffset),
  Offset(constraints.crossAxisExtent, trailingOffset),
);

By contrast, paintUpTo in the same method (line 331) positions children in paint coordinates with parentData.layoutOffset! - constraints.scrollOffset. Because the clip rect is not shifted by -constraints.scrollOffset, it is offset downwards by scrollOffset whenever the sliver is scrolled. As a result, expanding/collapsing children near the bottom of a scrolled TreeSliver are clipped out during the animation and abruptly pop in or out once the animation finishes and the clip layer is removed.

(Note: PR #194172 also noted this bug in its review follow-up as out of scope for that PR.)

Code sample
Code sample
import 'package:material_ui/material_ui.dart';

void main() => runApp(const MaterialApp(home: TreeSliverClipBug()));

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

  @override
  State<TreeSliverClipBug> createState() => _TreeSliverClipBugState();
}

class _TreeSliverClipBugState extends State<TreeSliverClipBug> {
  final List<TreeSliverNode<String>> _tree = [
    for (int i = 0; i < 20; i++)
      TreeSliverNode<String>(
        'Parent $i',
        children: [
          for (int j = 0; j < 4; j++) TreeSliverNode<String>('Child $i.$j'),
        ],
      ),
      TreeSliverNode<String>('Padding'),
      TreeSliverNode<String>('Padding'),
      TreeSliverNode<String>('Padding'),
      TreeSliverNode<String>('Padding'),
      TreeSliverNode<String>('Padding'),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('TreeSliver scrollOffset clip bug')),
      body: CustomScrollView(
        slivers: [
          TreeSliver<String>(
            tree: _tree,
            toggleAnimationStyle: const AnimationStyle(
              duration: Duration(milliseconds: 500),
            ),
          ),
        ],
      ),
    );
  }
}
Screenshots or Video
Screenshots / Video demonstration

(No dedicated video capture software on this work machine, Windows Snip tool too low framerate)

Logs
Logs
No errors or exceptions are thrown.
Flutter Doctor output
Doctor output
[√] Flutter (Channel stable, 3.50.0, on Microsoft Windows [Version 10.0.26200.9911], locale en-BE) [3.2s]
    • Flutter version 3.50.0 on channel stable at C:\Users\<user>\Flutter\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ab2912035e (3 weeks ago), 2026-11-09 08:50:21 -0800
    • Engine revision 371f77202a
    • Dart version 3.14.0
    • DevTools version 2.61.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

[√] Windows Version (Windows 11 or higher, 25H2, 2009) [8.0s]

[X] Android toolchain - develop for Android devices [1,316ms]
    X Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/to/windows-android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

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

[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2026 18.6.2) [1,272ms]
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools
    • Visual Studio Build Tools 2026 version 18.6.11822.322
    • Windows 10 SDK version 10.0.26100.0

[√] Connected device (3 available) [1,340ms]
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26200.9911]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 158.0.8127.88
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 149.0.4022.69

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

! Doctor found issues in 1 category.
Dominant language
Dart
Stars
182k
Forks
32k
Avg merge
1d 21h
Merged PRs (30d)
336

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from flutter/flutter

All issues in flutter/flutter

Similar issues

More Dart issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.