-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
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
| close(); |
and
| widget.onClosing(); |