auto_route_library
auto_route_library copied to clipboard
BackGesture is disabled only on iOs when using @CustomRoute
Is there any tricks we can use to enable that?
@wer-mathurin BackGesture is enabled in Custom routes? I'm not sure I understand your question!
@Milad-Akarie If you have a theme like this
final ThemeData myTheme = ThemeData(
pageTransitionsTheme: const PageTransitionsTheme(builders: {
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
TargetPlatform.android: FadeUpwardsPageTransitionsBuilder(),
}),
)
If i'm using AutoRoute(page:xxxxxx) Back gesture is working fine on Android and iOS
if you change it to CustomRoute(page:xxxxxx) BackGesture is working only on Android
@wer-mathurin are you using a CupertinoAutoRouter?
@Milad-Akarie : AdaptiveAutoRouter
@wer-mathurin I'm confused because it doesn't make sense to me that BackGesture is enabled on Android.
@Milad-Akarie
I wrap my Widget in a WillPopScope, doing some action and eventually calling context.router.pop()
That's is doing the trick for Android, but that's why I'm focussing on the iOS problem.
Just changing from AutoRoute to CustomRoute the behavior change without changing the code
@wer-mathurin AutoRoute
inherits it's type from AdaptiveAutoRouter
so it becomes AdaptiveRoute
, which on IOS uses CupertinoRoute
@wer-mathurin are you saying that your problem is on IOS will pop scope is not triggered when using BackGesture?
@Milad-Akarie Good catch. Is this something you can do in the library while they fix the problem https://github.com/flutter/flutter/issues/14203#issuecomment-540663717
@wer-mathurin the problem is with the WillPopScope
on ios when using CupertinoRoute
there isn't any workaround unless you rewrite the CupertinoPageRoute
class
bool get popGestureEnabled => _isPopGestureEnabled(this);
static bool _isPopGestureEnabled<T>(PageRoute<T> route) {
// If there's nothing to go back to, then obviously we don't support
// the back gesture.
if (route.isFirst)
return false;
// If the route wouldn't actually pop if we popped it, then the gesture
// would be really confusing (or would skip internal routes), so disallow it.
if (route.willHandlePopInternally)
return false;
// If attempts to dismiss this route might be vetoed such as in a page
// with forms, then do not allow the user to dismiss the route with a swipe.
if (route.hasScopedWillPopCallback)
return false;
// Fullscreen dialogs aren't dismissible by back swipe.
if (route.fullscreenDialog)
return false;
// If we're in an animation already, we cannot be manually swiped.
if (route.animation!.status != AnimationStatus.completed)
return false;
// If we're being popped into, we also cannot be swiped until the pop above
// it completes. This translates to our secondary animation being
// dismissed.
if (route.secondaryAnimation!.status != AnimationStatus.dismissed)
return false;
// If we're in a gesture already, we cannot start another.
if (isPopGestureInProgress(route))
return false;
// Looks like a back gesture would be welcome!
return true;
}
as you can see there it will check if there's a WillPopCallback it will prevent the user from using the gesture tho as I said you can rewrite the class so it can check the callback and determine if the user can pop or not
same issue
How to enable back gesture using CustomRoute on iOS @Milad-Akarie ?
same problem here with IOS, and CustomRoute