Stack Overflow Asked by JayVDiyk on January 21, 2021
Is it possible to intercept the event when the bottom sheet is being drag down, and show a message when it is about to close?
Try this,
i added bool variable that check bottomSheet is open or closed, (also this action i printout in appBar).
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
bool isOpen = false;
var bottomSheetController;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: isOpen?Text("Open Bottom Sheet"):Text("Closed Bottom Sheet"),
),
body:
FloatingActionButton(
onPressed: () {
setState(() {
isOpen = !isOpen;
});
print('clicked on the bottom sheet');
if(isOpen) {
bottomSheetController = showBottomSheet(
backgroundColor: Colors.transparent,
context: context,
builder: (ctx) {
return ClipRRect(
borderRadius: BorderRadius.only(
topRight: Radius.circular(20),
topLeft: Radius.circular(20),
),
child: Container(
height: 150,
color: Colors.black,
child: TextField()
),
);
});
bottomSheetController.closed.then((value) {
setState(() {
isOpen = !isOpen;
});
});
} else {
Navigator.of(context).pop();
setState(() {
isOpen = !isOpen;
});
}
},
child: isOpen?Icon(Icons.arrow_downward):Icon(Icons.arrow_upward),
),
);
}
}
Answered by shirsh shukla on January 21, 2021
This is not a definitive answer, but I'm posting here because it provides a direction and is too long for a comment (because of links).
BottomSheet class defines BottomSheetDragStartHandler which is a callback for when the user begins dragging the bottom sheet.
_ModalBottomSheet passes this as onDragStart and this as onDragEnd argument to it's BottomSheet child.
So in theory, if you really want to, you can implement custom bottom sheet following the example of _ModalBottomSheet and tailoring the stuff according to need.
Answered by happy_san on January 21, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP