Repository navigation
RouteObserver/NavigatorObserver.didPop no longer called on iOS back swipe #29596
Description
Hello, on master, deb, beta channel didPop no calls, it is bad, because need check screen pop,
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
class _BaseWidgetState extends State<BaseWidget>
with RouteAware, WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
routeObserver.subscribe(this, ModalRoute.of(context));
}
@override
void didPushNext() {
super.didPushNext();
print('didPushNext');
if (widget.pushNext != null) widget.pushNext();
}
@override
void didPop() {
super.didPop();
print('didPop');
if (widget.pop != null) widget.pop();
}
@override
void didPopNext() {
super.didPopNext();
print('didPopNext');
if (widget.popNext != null) widget.popNext();
}
@override
void didPush() {
super.didPush();
print('didPush');
if (widget.push != null) widget.push();
}
@override
void dispose() {
routeObserver.unsubscribe(this);
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
}
I test channel
- stable
//push next screen
flutter: didPushNext
flutter: didPush
-----swipe screen(iOS)
flutter: didPopNext
flutter: didPop
-----touch back button (Android)
flutter: didPopNext
flutter: didPop
test: successful
-
master
//push next screen
flutter: didPushNext
flutter: didPush
-----swipe screen(iOS)
no reaction!!!
-----touch back button (Android)
flutter: didPopNext
flutter: didPop -
dev
//push next screen
flutter: didPushNext
flutter: didPush
----- swipe screen(iOS)
no reaction!!!
-----touch back button (Android)
flutter: didPopNext
flutter: didPop -
beta
//push next screen
flutter: didPushNext
flutter: didPush
-----swipe screen(iOS)
no reaction!!!
-----touch back button (Android)
flutter: didPopNext
flutter: didPop
Flutter 1.3.12-pre.29 • channel master • https://github.com/flutter/flutter.git
Framework • revision af6e09f (34 hours ago) • 2019-03-18 21:40:21 -0700
Engine • revision 5088735
Tools • Dart 2.2.1 (build 2.2.1-dev.1.0 None)
Running flutter doctor...
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, v1.3.14-pre.7, on Mac OS X 10.14.3 18D109, locale ru-RU)
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.3)
[✓] Connected device (1 available)
• No issues found!
Activity
[-]RouteObserver can't didPop[/-][+]RouteObserver can't call didPop on iOS Swipe[/+]msw333 commentedon Mar 20, 2019
Might be related to #28756
xster commentedon Mar 26, 2019
Can you help us clarify what is the API you're trying to use? Since there are 2 'iOS swipe' mechanism that may be relevant to your described issue.
On the one hand, Flutter itself handles iOS back swipes within the Flutter navigation mechanism. That's related to #28756 but not related to WidgetsBinding etc.
On the other hand, you might be referring to executing an iOS back swipe one level higher on a FlutterViewController part of a UINavigationController that you have in your own native project. And you're manually calling FlutterViewController.popRoute. In that case, it's related to WidgetsBinding.
These 2 things are somewhat orthogonal. What scenario are you referring to?
1AlexFix1 commentedon Mar 26, 2019
I do Navigator.pushNamed then I do the swipe back and I do not get the message about didPop,
xster commentedon Mar 26, 2019
Thanks for the response. This might be a bug in our documentation for not being clearer. Those are orthogonal mechanisms. WidgetsBinding only observes platform triggered navigations against the ViewController or Activity etc.
To observe the Flutter side Navigator, pass a NavigatorObserver list into the Navigator constructor (or the Material/CupertinoApp etc).
Did I interpret the question correctly?
1AlexFix1 commentedon Mar 27, 2019
I think I understood, I'm sorry, I did not provide the full information in the question (full code), I, of course, pass the routeObserver to MaterialApp, I did everything as in the documentation https: //docs.flutter .io / flutter / widgets / RouteObserver -class.html and everything works fine on a stable branch, but on the remaining 3 branches didpop flutter is not called when swipe, if there was a transition using CupertinoPageRoute, however, if you press the button on android onBack, didPop is called
msw333 commentedon Mar 29, 2019
Can you show us how (example code)? There is no documentation on this. I think most people (including me) do it like this:
8 remaining items
xster commentedon Mar 29, 2019
Yes, it is related to #28728, which makes the solution to this tricky too. If you popped something and while it's animating, pushed something else, what should we call on the NavigatorObserver? Calling didPop is ambiguous because the route that's popped is no longer the top route by the time it's called.
alexelsn commentedon Apr 2, 2019
We are also desperately waiting for a fix. Do you have any update guys ;-)?
xster commentedon Apr 3, 2019
As @Hixie suggested, since the navigation is 'committed' as soon as the back swipe gesture's pointer is lifted, we can let the pop happen at the start of the final snap animation instead of at the end of it.
xster commentedon Apr 3, 2019
It can probably be worked out but it turned out not as easy as I thought because by calling pop earlier the TransitionRoute.didPop is rather specific on how it animates
flutter/packages/flutter/lib/src/widgets/routes.dart
Line 206 in 72a4083
whereas we want to be very particular about the snapping animation, duration and curve when we drop the back swipe gesture.
msw333 commentedon Apr 6, 2019
@xster, can you elaborate on the 'hacky' solution. I am doing the following and it is not triggered when page pops. Maybe I am missing out 'route' and 'previousRoute'? No idea what to insert. I haven't named my routes, but rely on Navigator.push:
xster commentedon Apr 8, 2019
Since the fix is out in #30422, you could potentially just patch the PR into your Flutter SDK and keep using didPop.
msw333 commentedon Apr 8, 2019
Any idea when it will be merged into the master? Not feeling well messing around on the SDK.
xster commentedon Apr 17, 2019
Sorry for the wait all. It's been fixed on master.
msw333 commentedon Apr 20, 2019
Leads to a new behavior on my iPhone X. After some 'using' of swipe gestures, they stop working. I can then only get back via BackButton. Then animation is much slower.
alexelsn commentedon Apr 22, 2019
Yes, the fix was also pretty important for us. But now, after some time, the swipe back stops working. Hope for new fix asap :-)
xster commentedon Apr 23, 2019
Thanks for reporting. #31471
github-actions commentedon Aug 30, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.