Skip to content

DraggableScrollableSheet from showModalBottomSheet snaps to unspecified extent #116982

Closed
flutter/packages
#12545

Description

@gidrokolbaska

Steps to Reproduce

  1. Paste the code from the sample below under MaterialApp's home property
  2. Run the app and press the bugs button
  3. A draggable scrollable sheet will appear.

Actual results:
Sometimes, when you want to dismiss the bottom scrollable sheet by dragging, it will stick to the bottom instead of disappearing, even though there are only 2 snap sizes specified (0.8 and 1.0):

2022-12-02.19.41.44.mov

Expected results:
Proper dismiss behavior should be implemented.

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

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            showModalBottomSheet(
              enableDrag: true,
              useSafeArea: true,
              clipBehavior: Clip.hardEdge,
              shape: const RoundedRectangleBorder(
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(20),
                  topRight: Radius.circular(20),
                ),
              ),
              context: context,
              isScrollControlled: true,
              builder: (context) {
                return DraggableScrollableSheet(
                  expand: false,
                  initialChildSize: 0.8,
                  snap: true,
                  snapSizes: const [0.8, 1.0],
                  builder: (context, scrollController) {
                    return CustomScrollView(
                      controller: scrollController,
                      physics: const ClampingScrollPhysics(),
                      slivers: [
                        SliverPersistentHeader(
                          delegate: TestSliverAppBar(),
                          pinned: true,
                        ),
                        SliverList(
                          delegate: SliverChildBuilderDelegate(
                            (_, index) => ListTile(
                              title: Text("Index: $index"),
                            ),
                            childCount: 50,
                          ),
                        )
                      ],
                    );
                  },
                );
              },
            );
          },
          child: const Text(
            'bugs',
          ),
        ),
      ),
    );
  }
}

class TestSliverAppBar extends SliverPersistentHeaderDelegate {
  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    return Container(
      color: Colors.pink,
    );
  }

  @override
  double get maxExtent => 100;

  @override
  double get minExtent => 50;

  @override
  bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) =>
      true;
}
Logs
[!] Flutter (Channel master, 3.6.0-14.0.pre.2, on macOS 12.6 21G115 darwin-arm64, locale ru-RU)
    • Flutter version 3.6.0-14.0.pre.2 on channel master at /Users/gidrokolbaska/Developer/flutter
    ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/2.16.0/libexec/bin/dart, which is not inside your
      current Flutter SDK checkout at /Users/gidrokolbaska/Developer/flutter. Consider adding
      /Users/gidrokolbaska/Developer/flutter/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7572ce907f (35 hours ago), 2022-12-01 01:07:29 -0500
    • Engine revision 51356bf895
    • Dart version 2.19.0 (build 2.19.0-444.0.dev)
    • DevTools version 2.20.0
    • 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 32.1.0-rc1)
    • Android SDK at /Users/gidrokolbaska/Library/Android/sdk
    • Platform android-32, build-tools 32.1.0-rc1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A400
    • CocoaPods version 1.11.2

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

[✓] Android Studio (version 2021.1)
    • Android Studio at /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 11.0.11+0-b60-7772763)

[✓] VS Code (version 1.73.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.34.0

[✓] Connected device (3 available)
    • iPhone 12 (mobile) • 070B14C3-C297-4A54-A136-A502B61105DF • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-16-0 (simulator)
    • macOS (desktop)    • macos                                • darwin-arm64   • macOS 12.6 21G115 darwin-arm64
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 108.0.5359.71

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

Activity

  1. gidrokolbaska commented on Dec 13, 2022

    @gidrokolbaska
    Author

    Hello, @Piinks! This is the 2nd part of the issue #116427

  2. changed the title [-]DraggableScrollableSheet which is called by showModalBottomSheet and contains Slivers has buggy behavior. Part 2[/-] [+]DraggableScrollableSheet from showModalBottomSheet snaps to unspecified extent[/+] on Dec 13, 2022
  3. Piinks commented on Dec 13, 2022

    @Piinks
    Contributor

    It looks like this is unexpected behavior based on the provided snapSizes. I wonder if the Scaffold bottom sheet dismissal handling is interfering with the draggable scrollable sheet's gestures.

  4. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: scrollingViewports, list views, slivers, etc.
    P2Important issues not at the top of the work list
    p: material_uimaterial_ui package in flutter/packages
    on Dec 13, 2022
  5. gidrokolbaska commented on Dec 14, 2022

    @gidrokolbaska
    Author

    It looks like this is unexpected behavior based on the provided snapSizes. I wonder if the Scaffold bottom sheet dismissal handling is interfering with the draggable scrollable sheet's gestures.

    yes, that's what I thought as well, but it's was still worth creating an issue for that because it might be that I'm just using DraggableScrollableSheet in conjunction with showModalBottomSheet incorrectly

  6. kamami commented on Feb 6, 2023

    @kamami

    Any progress here? this prevents us from calling DraggableScrolllableSheet via showModalBottomSheet...

  7. gnprice commented on Feb 24, 2023

    @gnprice
    Member

    As a partial diagnosis: I think the point where it sticks at is the minChildSize. By default that's 0.25, which is what we see in the repro video.

    (I haven't looked closer to understand how that causes this behavior.)

  8. absar commented on Apr 10, 2023

    @absar

    The minChildSize and maxChildSize are implicitly included in snap sizes even if you do not specify explicitly, that's why there is snap at minChildSize. However the real issue is when you fling it to close, it briefly stops at minChildSize before closing which gives a bad UX, @xu-baolin might have a clue

  9. julianniedermaier commented on Jun 16, 2023

    @julianniedermaier

    I've written a dirty workaround to have it look good on the UI side of things. Hope that helps

    #36283 (comment)

  10. yesilcimenahmet commented on Feb 8, 2025

    @yesilcimenahmet

    is there any progress here?

  11. gidrokolbaska commented on Apr 8, 2025

    @gidrokolbaska
    Author

    Seems like this has been fixed in #165557

  12. github-actions commented on Apr 30, 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.

  13. locked as resolved and limited conversation to collaborators on Apr 30, 2025
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.frameworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions