Skip to content

SliverFillRemaining(fillOverscroll: true) does not extend beyond the viewport size #141077

Closed

Description

@Jjagg

Steps to reproduce

Create a widget that builds a CustomScrollView with bouncing scroll physics and a single child: a SliverFillRemaining with hasScrollBody: false and fillOverscroll: true.

Expected results

The constraints passed to the child of SliverFillRemaining are expanded when overscrolling so the child can fill the overscroll area.

For my use case I'd like to customize the background color of the overscroll area so it has the same background as SliverFillRemainings child, which is different from the Scaffold background color.

This is the same use case as mentioned in #44353.
@Piinks
From this comment I believe the intent was to support this use case:

I like your idea of being able to use this sliver for just customizing the overscroll area separate from the background, without an actual child to draw otherwise in the scroll view. I'll see if this is something I can adjust to make possible. :)

You can see how the child is only stretched to a maximum size of the viewport by uncommenting the SizedBox in the sample code. The first 100 px of overscroll will be covered by SliverFillRemaining, but after that you'll see the scaffold's background color.

I think this happens because RenderSliverFillRemainingAndOverscroll uses SliverConstraints.remainingPaintExtent for the max extent and remainingPaintExtent does not grow beyond the viewport extent even when there is significant overscroll. That seems unintuitive to me; because of overscroll remainingPaintExtent should be able to get bigger than the viewport extent, right?

Actual results

The child is not stretched to fill the overscroll area.

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(
      home: Scaffold(
        body: Center(
          child: Container(
            height: 500,
            color: Colors.blue,
            child: CustomScrollView(
              physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
              slivers: [
                //const SliverToBoxAdapter(
                //  child: ColoredBox(
                //    color: Colors.green,
                //    child: SizedBox(height: 100),
                //  ),
                //),
                SliverFillRemaining(
                  hasScrollBody: false,
                  fillOverscroll: true,
                  child: Container(color: Colors.red),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

Example with the SizedBox commented; we see the scaffold background color immediately when overscroll starts:

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-07.at.18.23.22.mp4

Example with the SizedBox uncommented; we see the scaffold background color after overscroll exceeds 100 px:

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-07.at.18.23.55.mp4

Logs

No response

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.5, on macOS 14.1 23B2073 darwin-arm64, locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 15.1)
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google
    Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio (version 2023.1)
[✓] VS Code (version 1.85.1)
[✓] Connected device (2 available)
[✓] Network resources

! Doctor found issues in 2 categories.

Activity

  1. Jjagg commented on Jan 7, 2024

    @Jjagg
    ContributorAuthor

    When you only want to add a background color and not stretch other parts of the box widget wrapped in SliverFillRemaining you can workaround this issue by instead adding an empty SliverFillRemaining with the right background color. This makes the SliverFillRemaining smaller so will avoid the issue as long as there is enough content in the slivers before the final SliverFillRemaining. You would still run into this issue if the SliverFillRemaining would have to be larger than the viewport size to fill the overscroll area.

    I.e. instead of

    slivers: [
      SliverFillRemaining(
        child: ColoredBox(
          color: overscrollBg,
          child: MyWidget(),
        ),
      ),
    ]

    use

    slivers: [
      SliverToBoxAdapter(child: MyWidget()),
      SliverFillRemaining(
        child: ColoredBox(
          color: overscrollBg,
          child: SizedBox.expand(),
        ),
      ),
    ]

    Here's a reusable widget for it:

    class SliverTrailingOverscrollColor extends StatelessWidget {
      const SliverTrailingOverscrollColor({
        super.key,
        required this.color,
      });
    
      final Color color;
    
      @override
      Widget build(BuildContext context) {
        return SliverFillRemaining(
          hasScrollBody: false,
          fillOverscroll: true,
          child: ColoredBox(
            color: color,
            child: const SizedBox.expand(),
          ),
        );
      }
    }
  2. danagbemava-nc commented on Jan 8, 2024

    @danagbemava-nc
    Member

    Reproducible using the sample provided in the initial post.

    Labeling for further investigation

    flutter doctor -v
    [!] Flutter (Channel stable, 3.16.5, on macOS 14.1.2 23B92 darwin-arm64, locale en-GB)
        • Flutter version 3.16.5 on channel stable at /Users/nexus/dev/sdks/flutter
        ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutters/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutter. Consider adding /Users/nexus/dev/sdks/flutter/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutters/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutter. Consider adding /Users/nexus/dev/sdks/flutter/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 78666c8dc5 (3 weeks ago), 2023-12-19 16:14:14 -0800
        • Engine revision 3f3e560236
        • Dart version 3.2.3
        • DevTools version 2.28.4
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc1)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0-rc1
        • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.0)
        • Xcode at /Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer
        • Build 15A240d
        • CocoaPods version 1.14.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.3)
        • Android Studio at /Users/nexus/Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
        • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
        • Flutter plugin version 76.3.4
        • Dart plugin version 232.10072.19
    
    [✓] VS Code (version 1.85.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.80.0
    
    [✓] Connected device (4 available)
        • Pixel 7 (mobile) • 28291FDH2001SA            • android-arm64  • Android 14 (API 34)
        • Nexus (mobile)   • 00008020-001875E83A38002E • ios            • iOS 17.2.1 21C66
        • macOS (desktop)  • macos                     • darwin-arm64   • macOS 14.1.2 23B92 darwin-arm64
        • Chrome (web)     • chrome                    • web-javascript • Google Chrome 120.0.6099.199
        ! Error: Browsing on the local area network for Dean’s iPad. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    
    [✓] Flutter (Channel master, 3.18.0-19.0.pre.103, on macOS 14.1.2 23B92 darwin-arm64, locale en-GB)
        • Flutter version 3.18.0-19.0.pre.103 on channel master at /Users/nexus/dev/sdks/flutters
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 65fae87f2f (6 hours ago), 2024-01-08 00:12:26 -0500
        • Engine revision 702ae19c00
        • Dart version 3.3.0 (build 3.3.0-279.0.dev)
        • DevTools version 2.31.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc1)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0-rc1
        • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.0)
        • Xcode at /Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer
        • Build 15A240d
        • CocoaPods version 1.14.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.3)
        • Android Studio at /Users/nexus/Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
        • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
        • Flutter plugin version 76.3.4
        • Dart plugin version 232.10072.19
    
    [✓] VS Code (version 1.85.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.80.0
    
    [✓] Connected device (4 available)
        • Pixel 7 (mobile) • 28291FDH2001SA            • android-arm64  • Android 14 (API 34)
        • Nexus (mobile)   • 00008020-001875E83A38002E • ios            • iOS 17.2.1 21C66
        • macOS (desktop)  • macos                     • darwin-arm64   • macOS 14.1.2 23B92 darwin-arm64
        • Chrome (web)     • chrome                    • web-javascript • Google Chrome 120.0.6099.199
        ! Error: Browsing on the local area network for Dean’s iPad. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    
  3. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: scrollingViewports, list views, slivers, etc.
    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 Jan 8, 2024
  4. added
    P2Important issues not at the top of the work list
    on Jan 9, 2024
  5. github-actions commented on Sep 3, 2026

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

  6. locked as resolved and limited conversation to collaborators on Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.16Found to occur in 3.16found in release: 3.18Found to occur in 3.18frameworkflutter/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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions