I need to close a bottom sheet when the inner list is scrolled up. The bottom sheet contains only a list. According to the documentation, the parameter isScrollControlled in showModalBottomSheet is what I need. The documentation for the function.
The isScrollControlled parameter specifies whether this is a route for a bottom sheet that will utilize DraggableScrollableSheet. If you wish to have a bottom sheet that has a scrollable child such as a ListView or a GridView and have the bottom sheet be draggable, you should set this parameter to true.
My code:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: ModalBottomSheetSample(),
);
}
}
class ModalBottomSheetSample extends StatelessWidget {
Widget build(BuildContext context) {
return Center(
child: ElevatedButton(
child: const Text('showModalBottomSheet'),
onPressed: () {
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
enableDrag: true,
isDismissible: true,
builder: (BuildContext context) {
return Container(
height: 248,
child: ListView.builder(itemBuilder: (context, index) {
return ListTile(title: Text("i'm tile ${index}"));
}),
);},
);},
),
);
}
}
Modal BottomSheet is opened, but when I scroll the list up, it doesn't affect the sheet, it's not dragged down.
Why it doesn't work and how can I make this work?