Skip to content

Disable bottom sheet dismissal when dragging to min extent #127236

@monkeyswarm

Description

@monkeyswarm

Is there an existing issue for this?

Use case

We'd like to have a (persistent, non-modal) bottom sheet with a minimum height, which can not be dragged down to dismiss.

Currently (via Scaffold.showBottomSheet), Flutter will close the bottomSheet when the user has dragged to the minExtent. We do not want that behavior.

We can hackily get this behavior by wrapping our sheet (in this case, DraggableScrollableSheet) with a NotificationListener and swallowing the notifications before the parent sheet/Scaffold receives them. Obviously not a good solution.

Future<T?> showPersistentBottomSheet<T>({required BuildContext context}) {
  bool extentChanged(DraggableScrollableNotification notification) {
    // consume notification before it hits BottomSheet or Scaffold
    // This prevents dismissing the sheet when scrolled to its minChildSize
    return true;
  }

  final scaffold = Scaffold.of(context);
  return scaffold.showBottomSheet<T>(enableDrag: false, (_) {
    return NotificationListener<DraggableScrollableNotification>(
        onNotification: extentChanged,
        child: DraggableScrollableSheet(
          initialChildSize: 0.4,
          maxChildSize: 0.95,
          minChildSize: 0.4,
          expand: false,
          builder: (_, scrollController) =>
              ListView.builder(
                controller: scrollController,
                padding: EdgeInsets.zero,
                itemCount: 50,
                itemBuilder: (_, index) => Container(
                  color: Colors.grey,
                  child: Container(height: 30.0, child: Text('cell $index')),
                ),
              ),
        ));
  }).closed;
}

Proposal

@HansMuller suggested adding a flag for this desired behavior. E.g. Scaffold.showBottomSheet could have a bool dismissOnMinExtent=true parameter.

I've looked briefly at the internal handling between BottomSheet and Scaffold, we'll need to handle a few code paths, including hitting


and

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions