modal_bottom_sheet
modal_bottom_sheet copied to clipboard
Bug with WillPopScope in inside modal
I want to disable close inside modal but i catch this error.
https://user-images.githubusercontent.com/20646071/190980441-547a5748-7feb-4408-bd27-336011def787.mp4
My ModalWillPopScope
class ModalWillPopScope extends StatefulWidget {
final Widget child;
final WillPopCallback? onWillPop;
const ModalWillPopScope({
Key? key,
required this.child,
required this.onWillPop,
}) : super(key: key);
@override
State<ModalWillPopScope> createState() => _ModalWillPopScopeState();
}
class _ModalWillPopScopeState extends State<ModalWillPopScope> {
ModalRoute<dynamic>? _route;
ModalRoute<dynamic>? getModalRoute() {
final route = ModalRoute.of(context);
final navigator = Navigator.of(context);
final navigatorRoute = ModalRoute.of(navigator.context);
if (route is CupertinoModalBottomSheetRoute ||
route is MaterialWithModalsPageRoute) {
return route;
}
if (navigatorRoute is CupertinoModalBottomSheetRoute ||
navigatorRoute is MaterialWithModalsPageRoute) {
return navigatorRoute;
}
return null;
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (widget.onWillPop != null) {
_route?.removeScopedWillPopCallback(widget.onWillPop!);
}
_route = getModalRoute();
if (widget.onWillPop != null) {
_route?.addScopedWillPopCallback(widget.onWillPop!);
}
}
@override
void didUpdateWidget(ModalWillPopScope oldWidget) {
super.didUpdateWidget(oldWidget);
assert(_route == getModalRoute());
if (widget.onWillPop != oldWidget.onWillPop && _route != null) {
if (oldWidget.onWillPop != null) {
_route!.removeScopedWillPopCallback(oldWidget.onWillPop!);
}
if (widget.onWillPop != null) {
_route!.addScopedWillPopCallback(widget.onWillPop!);
}
}
}
@override
void dispose() {
if (widget.onWillPop != null) {
_route?.removeScopedWillPopCallback(widget.onWillPop!);
}
super.dispose();
}
@override
Widget build(BuildContext context) => widget.child;
}
Any news?
This bug is fixed on Android but not fixed on iOS
IOS Represent
https://user-images.githubusercontent.com/20646071/204449982-528299d7-4cd6-4780-b947-353146591aca.mov
Android Represent
https://user-images.githubusercontent.com/20646071/204450190-d699ba0f-3723-4480-9c5b-87387d6482c5.mp4
@ziqq Do you have any updates or solution for this issue? There is still same bugs in iOS
@SuhwanCha No i don't have solution. I'm still waiting for the author's decision.
Why Author never answer ?!
@greedy-brady because he doesn't have to.
I'm facing the same issue, btw
I stumbled above a similar behaviour while migrating from deprecated WillPopScope
to PopScope
.
For me it helped to add a bit of delay to the Future that returns false:
Future.delayed(Duration(milliseconds: 500), () => false)
Maybe it is worth to also try this approach for the problem described in this issue here.
I stumbled above a similar behaviour while migrating from deprecated
WillPopScope
toPopScope
. For me it helped to add a bit of delay to the Future that returns false:Future.delayed(Duration(milliseconds: 500), () => false)
Maybe it is worth to also try this approach for the problem described in this issue here.
No it's not working. Can u get your full variant?
I basically forked this repo and fixed this problem for me (in a quiet bad way): https://github.com/masewo/modal_bottom_sheet/blob/36a1cfebb4643b89f871aefe57671a6873d173ee/modal_bottom_sheet/lib/src/bottom_sheet_route.dart#L108 After this change the modal sheet was not stuck anymore on half way.
I basically forked this repo and fixed this problem for me (in a quiet bad way): https://github.com/masewo/modal_bottom_sheet/blob/36a1cfebb4643b89f871aefe57671a6873d173ee/modal_bottom_sheet/lib/src/bottom_sheet_route.dart#L108 After this change the modal sheet was not stuck anymore on half way.
Hi @masewo, PopScope work correctly?