Can't swipe to dismiss scrollable Bottom Sheet
Per @dnfield https://github.com/flutter/flutter/issues/31739#issuecomment-511459403
Use case
See the Crane Material sample and Google I/O 2019
These both feature a bottom sheet that slides up (in the case of I/O, you select "Events" and the hit the "Filter" FAB) and scrolls.
With the I/O app, if you continue to swipe down when scrolled to the top, it will start to drag and then dismiss when a threshold is reached.
If the threshold is not reached (or you swipe upwards) then the bottom sheet will not be dismissed and it'll rebound to the top of the screen.
Proposal
I'd think this should be a part of DraggableScrollableSheet as mentioned in #31739, but maybe it makes sense to bake the logic into the Bottom Sheet itself?
I've tried both modal and non-modal bottom sheets with and without the DraggableScrollableSheet, and can't seem to make this work as is.
The current issue with the DraggableScrollableSheet is that you can't have the sheet be maximized all the time. (Since, as I mentioned in https://github.com/flutter/flutter/issues/31739#issuecomment-511241746, any swipe will immediately dismiss the BottomSheet rather than scroll the CustomScrollView)
It would be super helpful if you had a gif/youtube/video of this behavior. I think I know what you're talking about, but I haven't used the apps you're referring to and I'm not sure which part to look for.
@dnfield See https://www.youtube.com/watch?v=95MUkecOta4
I wasn't able to get it to "rebound" while recording, but I'm pretty sure I've seen it bounce back to the top if a certain threshold isn't met.
Edit: First dismiss is dragging from the app bar. Second dismiss is from dragging the list after reaching the top (similar behavior to DraggableScrollableSheet). I had to release (after reaching the top of the list) and then drag down again.
I thought the bottom sheet was working this way - the first time you hit the top of the list it will bounce, the second time it will actually drag down. I feel like I'm missing something in the desired behavior though.
@dnfield I've tried both
_scaffoldKey.currentState.showBottomSheet(
_buildBottomSheet,
);
and
showModalBottomSheet(
context: context,
builder: _buildBottomSheet,
isScrollControlled: true,
);
where _buildBottomSheet is a Widget Function(BuildContext) that contains a CustomScrollView.
Nothing seems to do the drag-to-dismiss except when wrapped in a DraggableScrollableSheet.
Do I need to pass in a special ScrollController?
You have to use a DraggableScrollableSheet for that behavior to work.
@dnfield Ok. So how do I get the DraggableScrollableSheet to rebound back to maxChildSize unless the minChildSize threshold is passed?
I'm currently using this:
DraggableScrollableSheet(
builder: scroll,
initialChildSize: 1.0,
minChildSize: 0.9,
);
Unfortunately, the user can wind up with it sticking between 1.0 and 0.9, which looks a little awkward.
Unfortunately this isn't really documented well at all, and in trying to do it I'm finding some other bugs.
I think this should be possible, but it may take me a little while to get back to it. If you have a proposal for fixing it we could review a PR for it as well.
Are there any updates on this?
Hello @rbluethl, I built a package that supports scrollable ModalBottomSheets. https://github.com/jamesblasco/modal_bottom_sheet
Instead of showModalBottomSheet, it would be:
showMaterialModalBottomSheet(
context: context,
builder: (context, scrollController) => Container(),
})
Hope it can help you until this is officially implemented.
Any update on this? showModalBottomSheet not able to dismiss when swipe down.
Any news on this?
Hello @rbluethl, I built a package that supports scrollable ModalBottomSheets. https://github.com/jamesblasco/modal_bottom_sheet
Instead of
showModalBottomSheet, it would be:showMaterialModalBottomSheet( context: context, builder: (context, scrollController) => Container(), })Hope it can help you until this is officially implemented.
I tried using this plugin, happen to fix the issue of dismiss on scroll; but it goes over the app bar when the scrollable body is too long like I found here
Hey, @pranayairan your issue is a bit off-topic. For issues related to the package use https://github.com/jamesblasco/modal_bottom_sheet/issues/add
I will be happy to help you there solve this 🙂
officially update on this ?
Hello @rbluethl, I built a package that supports scrollable ModalBottomSheets. https://github.com/jamesblasco/modal_bottom_sheet
Instead of
showModalBottomSheet, it would be:showMaterialModalBottomSheet( context: context, builder: (context, scrollController) => Container(), })Hope it can help you until this is officially implemented.
Unfortunately, the package has some bugs and looks like it's not maintained anymore. The official fix is needed.
I've managed to do it with the following :
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
isScrollControlled: true,
isDismissible: true,
context: context,
builder: (context){
return DraggableScrollableSheet(
expand: false,
initialChildSize: 1,
// minChildSize: 1,
snap: true,
builder: (context, scrollController) {
return SingleChildScrollView(
controller: scrollController,
children:[],
);
},
);
},
);
I've managed to do it with the following :
showModalBottomSheet( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16), ), isScrollControlled: true, isDismissible: true, context: context, builder: (context){ return DraggableScrollableSheet( expand: false, initialChildSize: 1, // minChildSize: 1, snap: true, builder: (context, scrollController) { return SingleChildScrollView( controller: scrollController, children:[], ); }, ); }, );
Unfortunately, unless there's a workaround, this removes the nice behaviour modalBottomSheet has of making the sheet the same height as its contents.
I think we want to drag and tap the background to dismiss the sheet. However, we can't do these features at the same sheet.
for example, if we want to drag the background to dismiss the sheet, we can't tap the background to dismiss the sheet...
please see this video and code first I clicked the background (red area) but I couldn't dismiss it. second, I dragged to dismiss it.
Code sample
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('title'),
),
body: Center(
child: ElevatedButton(
onPressed: () => showModalBottomSheet(
barrierColor: Colors.yellow.withOpacity(0.5),
backgroundColor: Colors.red.withOpacity(0.5),
useRootNavigator: true,
context: context,
isDismissible: true,
isScrollControlled: true,
builder: (context) => DraggableScrollableSheet(
expand: true,
builder: (_, controller) => Container(
color: Colors.white,
child: ListView.builder(
controller: controller,
itemBuilder: (_, index) => ListTile(
title: Text(index.toString()),
),
),
),
),
),
child: const Text('open modal'),
),
),
);
}
}
https://user-images.githubusercontent.com/52235899/165458758-358aba3b-6f13-48d3-af8f-b869b50ef2d8.mov
Any update on this? showModalBottomSheet is not able to dismiss when swiping down.
that's a very bad thing that lots of people have an issue.
even having an issue with the status bar even though I used the safe area.
https://user-images.githubusercontent.com/14329287/180138571-d1d0db35-c05f-47c3-a05b-3640fb7969ec.mp4
This is still a thing. Would be nice to have it in place