Not sure if this is exactly what you're looking for but you could return a StatefulWidget in the showModalBottomSheet
builder and in that widget trigger a callback with the deactivate
or dispose
overrides. Deactivate is triggered first.
To trigger a callback you'd need to pass that function into the StatefulWidget
's constructor.
e.g.
void callback() {
debugPrint('>>> my callback triggered');
}
void showMyModalBottomSheet() {
showModalBottomSheet(
context: context,
builder: (context) {
return MyBottomSheetWidget(
callback: callback,
);
},
);
}
class MyBottomSheetWidget extends StatefulWidget {
final VoidCallback callback;
const MyBottomSheetWidget({
Key key,
this.callback,
}) : super(key: key);
@override
State<MyBottomSheetWidget> createState() => _MyBottomSheetWidgetState();
}
class _MyBottomSheetWidgetState extends State<MyBottomSheetWidget> {
@override
void deactivate() {
debugPrint('>>> bottom sheet closing');
widget.callback(); // This will be trigger when the bottom sheet finishes closing
super.deactivate();
}
@override
Widget build(BuildContext context) {
return Container();
}
}