Skip to content

DecoratedSliver inconsistency with pinned header or reversed Scrollable #179801

Description

@zemanux

Steps to reproduce

  1. Create a pinned header wrapped with DecoratedSliver in a CustomScrollView with physics set to BouncingScrollPhysics()
  2. Scroll down (or up if CustomScrollView)
  3. Try overscroll to test decoration stretch.

Expected results

The DecoratedSliver should always wrap the headers.

Actual results

Decoration is messy.

Code sample

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

void main() {
  runApp(const MaterialApp(home: MyApp()));
}

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

  @override
  Widget build(BuildContext context) => Scaffold(
    body: Padding(
      padding: const EdgeInsets.symmetric(horizontal: 64.0),
      child: CustomScrollView(
        reverse: true,
        physics: const BouncingScrollPhysics(),
        slivers: <Widget>[
          const _DecoratedSliver(
            isEnabled: true,
            // Here a simple SliverAppBar is used to demonstrate a pinned header sliver.
            sliver: SliverAppBar(
              pinned: true,
              stretch: true,
              expandedHeight: 100.0,
              surfaceTintColor: Colors.transparent,
              backgroundColor: Colors.transparent,
              flexibleSpace: FlexibleSpaceBar(title: Text('My header')),
            ),
          ),
          const _DecoratedSliver(
            sliver: PinnedHeaderSliver(child: ListTile(title: Text('A pinned header sliver'))),
          ),
          _DecoratedSliver(
            sliver: SliverMainAxisGroup(
              slivers: [
                PinnedHeaderSliver(
                  child: SizedBox(height: 150, child: const Center(child: Text('A SliverToBoxAdapter'))),
                ),
                SliverList.builder(
                  itemBuilder: (BuildContext context, int index) => ListTile(title: Text('Item $index')),
                  itemCount: 50,
                ),
              ],
            ),
          ),
        ],
      ),
    ),
  );
}

class _DecoratedSliver extends StatelessWidget {
  const _DecoratedSliver({this.isEnabled = true, required this.sliver});

  final bool isEnabled;
  final Widget sliver;

  @override
  Widget build(BuildContext context) => isEnabled
      ? DecoratedSliver(
          decoration: BoxDecoration(
            border: Border.all(),
            borderRadius: BorderRadius.circular(8),
            gradient: const LinearGradient(
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
              colors: [Colors.blue, Colors.purple],
            ),
          ),
          sliver: sliver,
        )
      : sliver;
}

Screenshots or Video

Details

Try with reverse true or false.

Screenshots / Video demonstration
decorated_sliver.mp4

CustomScrollView.reverse set to true

decorated_sliver_reverse.mp4

Logs

No response

Flutter Doctor output

Doctor output
[✓] Flutter (Channel master, 3.40.0-1.0.pre-145, on macOS 26.1 25B78 darwin-arm64, locale fr-FR) [2,7s]
    • Flutter version 3.40.0-1.0.pre-145 on channel master at /Users/emmanuel_lefebvre/fvm/versions/master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 6e1aa82352 (88 minutes ago), 2025-12-12 11:32:22 -0500
    • Engine revision 2c6cd4a98d
    • Dart version 3.11.0 (build 3.11.0-235.0.dev)
    • DevTools version 2.53.0
    • Pub download mirror https://artifact.socrate.vsct.fr/artifactory/api/pub/all-pub
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations,
      enable-native-assets, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1) [2,4s]
    • Android SDK at /Users/emmanuel_lefebvre/Library/Android/sdk
    • Emulator version 36.2.12.0 (build_id 14214601) (CL:N/A)
    • Platform android-36, build-tools 35.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.8+-14196175-b1038.72)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 26.1.1) [2,1s]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 17B100
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [6ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Connected device (3 available) [7,3s]
    • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64  • Android 15 (API 35) (emulator)
    • macOS (desktop)             • macos         • darwin-arm64   • macOS 26.1 25B78 darwin-arm64
    • Chrome (web)                • chrome        • web-javascript • Google Chrome 143.0.7499.110

[✓] Network resources [717ms]
    • 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.38Found to occur in 3.38found in release: 3.40Found to occur in 3.40frameworkflutter/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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions