Skip to content

Last item in the SliverMainAxisGroup list, performs an upward animation when it is time to change the PinnedHeaderSliver (Flutter 3.32) #173274

Description

@danielparsan

Steps to reproduce

  1. Run the provided minimal Flutter project or code sample.
  2. Scroll down slowly through the list until you reach the last items of any group.
  3. Observe how the pinned header behaves as the last item approaches the top of the screen.

✅ Note: This issue only occurs on Flutter 3.32+. It worked correctly in Flutter 3.29.

Expected results

When scrolling a long list grouped with SliverMainAxisGroup and PinnedHeaderSliver, the pinned header should remain fixed at the top until the next header scrolls in and replaces it.

The last list item should not push the header early. The header should only be replaced when the scroll reaches the next header.

Actual results

In Flutter 3.32, using SliverMainAxisGroup with PinnedHeaderSliver causes the header to be pushed too early when reaching the last item of the list.

This behavior did not happen in Flutter 3.29, where the sticky header was behaving as expected.

Code sample

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

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Bug',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Sliver MainAxis Group Bug'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final List<_Group> groupedItems = [
    _Group(name: 'Owned', items: List.generate(4, (_) => _MyItem())),
    _Group(name: 'Wishlist', items: List.generate(5, (_) => _MyItem())),
    _Group(name: 'Recently Played', items: List.generate(3, (_) => _MyItem())),
    _Group(name: 'Recently Added', items: List.generate(4, (_) => _MyItem())),
    _Group(name: 'Recently Updated', items: List.generate(6, (_) => _MyItem())),
    _Group(name: 'Recently Played', items: List.generate(2, (_) => _MyItem())),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.blue,
        title: Text(widget.title),
      ),
      body: CustomScrollView(
        slivers: [
          const SliverPadding(padding: EdgeInsets.only(top: 4)),
          for (final group in groupedItems)
            SliverMainAxisGroup(
              key: ValueKey(group),
              slivers: [
                PinnedHeaderSliver(
                  child: _MyHeaderListItem(group: group.name),
                ),
                SliverPrototypeExtentList.builder(
                  // Prevents the sliverList items from being kept in memory when they are not visible.
                  addAutomaticKeepAlives: false,
                  prototypeItem: _MyItem(),
                  itemBuilder: (context, index) => _MyItem(),
                  itemCount: group.items.length,
                ),
              ],
            )
        ],
      ),
    );
  }
}

class _Group {
  final String name;
  final List<dynamic> items;
  _Group({required this.name, required this.items});
}

class _MyHeaderListItem extends StatelessWidget {
  const _MyHeaderListItem({required this.group});
  final String group;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(12),
      child: Container(
        decoration: BoxDecoration(
          gradient: const LinearGradient(colors: [Colors.blueGrey, Colors.lightBlue]),
          borderRadius: BorderRadius.circular(20),
        ),
        padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
        child: Text(group, style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
      ),
    );
  }
}

class _MyItem extends StatelessWidget {
  const _MyItem();

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
      padding: const EdgeInsets.all(8),
      decoration: BoxDecoration(
        color: Colors.blueGrey[300],
        borderRadius: BorderRadius.circular(12),
        boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 4, offset: const Offset(0, 2))],
      ),
      child: InkWell(
        onTap: () => {},
        child: Row(
          children: [
            Container(
              width: 60,
              height: 90,
              decoration: BoxDecoration(
                color: Colors.blue,
                borderRadius: BorderRadius.circular(8),
              ),
            ),
            const SizedBox(width: 8),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text('🎏 Lorem ipsum dolor', maxLines: 1, overflow: TextOverflow.ellipsis),
                  const SizedBox(height: 4),
                  Text('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
                      maxLines: 2, overflow: TextOverflow.ellipsis, style: TextStyle(color: Colors.black54)),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration Image

https://drive.google.com/file/d/1TsqpM5gKFeodYk1LvUpmjjnqElmZGnop/view?usp=sharing

Logs

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.32.7, on macOS 15.3 24D60 darwin-x64, locale es-ES)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Android Studio (version 2021.3)
[✓] Android Studio (version 2023.3)
[✓] VS Code (version 1.102.3)
[✓] Connected device (4 available)
[✓] Network resources

Activity

  1. tirth-patel-nc commented on Aug 5, 2025

    @tirth-patel-nc
    Member

    Thanks for the detailed report. Appreciate it @danielparsan! Seeing the same behaviour with latest SDK versions with provided code sample and steps. however, it's not reproducible on 3.29.3, so marking this as a regression.

    stable : 3.32.8
    master : 3.33.0-1.0.pre-1278
    

    Bisected to #163528

    Bisect Logs
    tirthpatel@Tirths-MacBook-Pro au5 % cd ~/Development/flutter_stable_latest/flutter 
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect start
    status: waiting for both good and bad commits
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect bad
    status: waiting for good commit(s), bad commit known
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect good ea121f8
    Bisecting: a merge base must be tested
    [010c8a806bccad64ab9972286b85dd24ca98441f] Revert "Autocomplete Options Width" (#161666)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect good
    Bisecting: 658 revisions left to test after this (roughly 9 steps)
    [07503bbc82a7372a6a685e5b5d1406d139b8353c] [macOS] Prepare FlutterKeyboardManager for multi-view (#163962)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect bad 
    Bisecting: 328 revisions left to test after this (roughly 8 steps)
    [9438fd44712be71b33c9c6f325110be268dbec47] [Android] add runtime flag to determine if HCPP is supported. (#163004)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect good
    Bisecting: 164 revisions left to test after this (roughly 7 steps)
    [3decd62f3af408bade757aa091101b4bf1b90a90] Revert "Create g3_bug.yml" (#163757)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect good
    Bisecting: 82 revisions left to test after this (roughly 6 steps)
    [99e1a0652c2a2d0b692d9d02e0f4263e1af1a3d6] Fix extra numbers showing up when enabling VoiceControl (#163593)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect bad 
    Bisecting: 40 revisions left to test after this (roughly 5 steps)
    [4973143100f32bbe4c92bce45ffbf0abc896096f] Roll Skia from 4bee660601de to 72f949950adb (1 revision) (#163948)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect good
    Bisecting: 20 revisions left to test after this (roughly 4 steps)
    [271cb8c8c5c7c023e35fa982e9a1d32dfaccdf68] Add BorderRadiusGeometry to Divider Widget for Customisable Border Radius (#163414)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect bad 
    Bisecting: 9 revisions left to test after this (roughly 3 steps)
    [1e2583eff25200b10f01d1fc2d13e7936fba57d2] [ui] Fix ImageFilter.shader equality to consider uniform values. (#163348)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect good
    Bisecting: 4 revisions left to test after this (roughly 2 steps)
    [a4a5a33cfad5e11461d192f76edce6c220de2bdd] Roll .ci.yaml changes into the LUCI configuration only when the master branch is updated (#163897)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect good
    Bisecting: 2 revisions left to test after this (roughly 1 step)
    [ebc7d244d365a8bb5ea3b7f1d8c5dc87107ab44f] Roll Skia from 994168b1ba10 to a141a3ceef87 (1 revision) (#164023)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect good
    Bisecting: 0 revisions left to test after this (roughly 1 step)
    [4e39d13a6f67fa04a9dc424cd20663da9b81301b] SliverMainAxisGroup multiple PinnedHeaderSliver children (#163528)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect bad 
    Bisecting: 0 revisions left to test after this (roughly 0 steps)
    [7535cb10bcd4565032f68e1b975875f7686a955e] Move `AndroidRenderingApi` from `common` to `shell/platform/android` (#163796)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect good
    4e39d13a6f67fa04a9dc424cd20663da9b81301b is the first bad commit
    commit 4e39d13a6f67fa04a9dc424cd20663da9b81301b
    Author: yim <[email protected]>
    Date:   Tue Feb 25 13:53:03 2025 +0800
    
        SliverMainAxisGroup multiple PinnedHeaderSliver children (#163528)
        
        Fixes: #155758
        
        ## Pre-launch Checklist
        
        - [x] I read the [Contributor Guide] and followed the process outlined
        there for submitting PRs.
        - [x] I read the [Tree Hygiene] wiki page, which explains my
        responsibilities.
        - [x] I read and followed the [Flutter Style Guide], including [Features
        we expect every widget to implement].
        - [x] I signed the [CLA].
        - [x] I listed at least one issue that this PR fixes in the description
        above.
        - [ ] I updated/added relevant documentation (doc comments with `///`).
        - [x] I added new tests to check the change I am making, or this PR is
        [test-exempt].
        - [x] I followed the [breaking change policy] and added [Data Driven
        Fixes] where supported.
        - [x] All existing and new tests are passing.
        
        If you need help, consider asking for advice on the #hackers-new channel
        on [Discord].
        
        <!-- Links -->
        [Contributor Guide]:
        https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
        [Tree Hygiene]:
        https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
        [test-exempt]:
        https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
        [Flutter Style Guide]:
        https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
        [Features we expect every widget to implement]:
        https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
        [CLA]: https://cla.developers.google.com/
        [flutter/tests]: https://github.com/flutter/tests
        [breaking change policy]:
        https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
        [Discord]:
        https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
        [Data Driven Fixes]:
        https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
    
     .../flutter/lib/src/rendering/sliver_group.dart    | 96 ++++++++++++----------
     .../test/widgets/sliver_main_axis_group_test.dart  | 84 +++++++++++++++++++
     2 files changed, 135 insertions(+), 45 deletions(-)
    tirthpatel@Tirths-MacBook-Pro flutter % 
    3.29.3 3.32.8 & 3.33.0-1.0.pre-1278
    Screen.Recording.2025-08-05.at.7.03.55.PM.mov
    Screen.Recording.2025-08-05.at.7.05.01.PM.mov
  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: scrollingViewports, list views, slivers, etc.
    p: material_uimaterial_ui package in flutter/packages
    c: regressionIt was better in the past than it is now
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Aug 5, 2025
  3. added
    P1High-priority issues at the top of the work list
    and removed
    c: regressionIt was better in the past than it is now
    f: scrollingViewports, list views, slivers, etc.
    P1High-priority issues at the top of the work list
    on Aug 5, 2025
  4. 5 remaining items

  5. self-assigned this
    on Aug 6, 2025
  6. danielparsan commented on Aug 7, 2025

    @danielparsan
    Author

    Thanks for confirming that, @tirth-patel-nc . I really appreciate you checking it out, and I also thank all the members who are working together to resolve this issue.

  7. added a commit that references this issue on Aug 12, 2025
    ed13140
  8. added a commit that references this issue on Aug 19, 2025
    264bf7d
  9. github-actions commented on Aug 26, 2025

    @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.

  10. locked as resolved and limited conversation to collaborators on Aug 26, 2025
  11. added a commit that references this issue on Sep 18, 2025
    1fca97d
  12. added a commit that references this issue on Sep 22, 2025
    290cea1
  13. added a commit that references this issue on Nov 21, 2025
    76d3933
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listc: regressionIt was better in the past than it is nowf: scrollingViewports, list views, slivers, etc.found in release: 3.32Found to occur in 3.32found in release: 3.33Found to occur in 3.33frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesr: 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