Skip to content

Wrong maxScrollObstructionExtent in SliverResizingHeader #162661

@ghost

Description

The maxScrollObstructionExtent field of SliverGeometry in SliverResizingHeader is set to childExtent, but should be minExtent.

Steps to reproduce

Create a NestedScrollView with SliverResizingHeader as header, wrapped in a SliverOverlapAbsorber as the widgets.NestedScrollView.1 sample. For SliverResizingHeader, set minExtentPrototype to a SizedBox of height 50, and maxExtentPrototype to height 100.

Expected results

  • On first render, the height of the header is 100px.
  • Scrolling down 50px, the height of the header is 50px.
  • Scrolling down another 50px, the height of the header is still 50px.

Actual results

The height of the header is always 100px.

Code sample

Sample based on `widgets.NestedScrollView.1`
import 'package:flutter/material.dart';

/// Flutter code sample for [NestedScrollView].

void main() => runApp(const NestedScrollViewExampleApp());

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: NestedScrollViewExample(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    final List<String> tabs = <String>['Tab 1', 'Tab 2'];
    return DefaultTabController(
      length: tabs.length, // This is the number of tabs.
      child: Scaffold(
        body: NestedScrollView(
          headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
            // These are the slivers that show up in the "outer" scroll view.
            return <Widget>[
              SliverOverlapAbsorber(
                handle:
                    NestedScrollView.sliverOverlapAbsorberHandleFor(context),
                sliver: SliverResizingHeader(
                  minExtentPrototype: SizedBox(height: 50),
                  maxExtentPrototype: SizedBox(height: 100),
                  child: Material(
                    color: Colors.red,
                    child: Container(),
                  ),
                ),
              ),
            ];
          },
          body: TabBarView(
            children: tabs.map((String name) {
              return SafeArea(
                top: false,
                bottom: false,
                child: Builder(
                  builder: (BuildContext context) {
                    return CustomScrollView(
                      key: PageStorageKey<String>(name),
                      slivers: <Widget>[
                        SliverOverlapInjector(
                          // This is the flip side of the SliverOverlapAbsorber
                          // above.
                          handle:
                              NestedScrollView.sliverOverlapAbsorberHandleFor(
                                  context),
                        ),
                        SliverPadding(
                          padding: const EdgeInsets.all(8.0),

                          sliver: SliverFixedExtentList(

                            itemExtent: 48.0,
                            delegate: SliverChildBuilderDelegate(
                              (BuildContext context, int index) {

                                return ListTile(
                                  title: Text('Item $index'),
                                );
                              },
                              childCount: 30,
                            ),
                          ),
                        ),
                      ],
                    );
                  },
                ),
              );
            }).toList(),
          ),
        ),
      ),
    );
  }
}

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.27.2, on Arch Linux
    6.13.0-arch1-1, locale en_US.UTF-8)
    • Flutter version 3.27.2 on channel stable at
      /home/cloud/fvm/versions/3.27.2
    • Upstream repository
      https://github.com/flutter/flutter.git
    • Framework revision 68415ad1d9 (3 weeks ago), 2025-01-13
      10:22:03 -0800
    • Engine revision e672b006cb
    • Dart version 3.6.1
    • DevTools version 2.40.2

Same on master.

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.27Found to occur in 3.27found in release: 3.29Found to occur in 3.29frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: 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