-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PopScope seems to be incompatible with GoRouter #138737
Comments
Thanks for filing this and the detailed explanation. stable, master flutter doctor -v
|
I am actively working on this. It will have to wait for #137792 before I can fix this issue |
Hi @btrautmann. I look into your reproduce_repo. I see you use |
Our team uses Edit: Just to clarify, my usage of |
I'm encountering an issue with local notifications. When I click on a notification to open the detail page and then press the physical back button, the onPopInvoked method is not being called, even though the canPop value is false. But its work when I clicked on back button in the appbar. |
I couldn't find anyone else mentioning this but Note: Most of the code was copied from Flutter's official
|
I have the same issues in my cases i'm using only pushnamed in all routes |
@chunhtai |
Hello everyone. Are there any updates or workarounds? This issue is affecting our users and it's very painful. Is there any possible solution that will also work with the predictive back on Android? Or maybe someone has switched from GoRouter to something else and can highlight some of the benefits of that? Because this is also something we are considering... |
My only workaround for this is to stay in 12.1.3 in the meantime |
That's a great workaround @limitless-brain !! 🎉 (Or fix even, depending on your use case.) Tested successfully with import 'dart:developer';
import 'package:flutter/material.dart';
class PrePopWidget extends StatelessWidget {
const PrePopWidget({
super.key,
required this.child,
});
final Widget child;
@override
Widget build(BuildContext context) {
return BackButtonListener(
child: child,
onBackButtonPressed: () async {
log('[pre_pop_widget] [onBackButtonPressed]');
if (shouldNotPop) {
// Let the system know we've got this.
return Future.value(true);
}
// Let the system handle the back button press, which typically pops the route.
return Future.value(false);
},
);
}
} |
Did you try this solution on browser ? In my case it is not working on browser's back button. I am also using go_router 13.2.2 |
I did not. Good use-case catch! |
Any updates? Still reproducible in Go Router version [go_router: ^13.2.4] |
God bless you!! |
There is one problem here. If I push another page and then try to back, BackButtonListener would be called on the first page. How to solve this problem? |
Try this.
|
Been following this, I've implemented the BackButtonListener in place of all my WillPopScope and it handles fine on every page EXCEPT on my top level StatefulShellRoute. BackButtonListener isn't even being called there. Side quest, if anyone know a better way of handling both swipe and taping of the top tab buttons as I kind of had to get creative to make sure it was working. Edit: learning how to properly paste code, sorry, should be better now.
|
Seems like need to go back to basics and use Navigation 1.0. Easy and effective. |
This issue is assigned to @chunhtai but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks! |
How to listen for physical back button on A page as the initial page? Or A use I use
|
Any news? |
There is no good solution to resolve this question. It is still exists. We hope that the issus will be fixed. |
Oh, it works with go_router 12.x and Android's predictive back disabled (android:enableOnBackInvokedCallback="false"). Ideally, it should work with go_router 14.x and Android's predictive back enabled android:enableOnBackInvokedCallback="true". |
I've been looking into AutoRoute: https://pub.dev/packages/auto_route. It uses code generation (not a big deal) but seems less complex overall and is feature complete. |
With enableOnBackInvokedCallback=false, PopScope() and go router 14.2.0 work well on Android 14. |
We've fully transitioned to AutoRoute and it has been a LOT less complex and easier to integrate overall, in my experience. Not only that, a lot of the numerous backlogged bugs that plague go_router aren't issues in AutoRoute. |
How hard was the migration? I am doubting to migrate as well, but am reluctant to do all the migration stuff.. |
@BramMusters works fine for now, |
I did an initial test build where I took some of our most complicated routing and tried it with AutoRoute, including understanding the API took a day. It was straightforward and the API is well documented. After that, it took me a day(ish) to fully transition. In fact, I was able to remove a lot of code we had around GoRouter because of how much of the code gen takes care of a lot of common routing problems. |
the framework change is landed, I have to wait for next stable release before I can fix the incompatibility in go_router |
I've read through this thread and haven't really seen a simple workaround for both platforms. Here is mine for now. So My workaround on
I don't see when |
Is there an existing issue for this?
Steps to reproduce
Original comment was made at #138525 (comment) but I'm pasting here:
[...] our team was investigating
PopScope
and found some interesting behavior that can be reproduced using this repo. I don't believe this component is behaving as described in the docs.Using GoRouter APIs on iOS 17:
canPop
is set totrue
, user can go back via app bar or back button butonPopInvoked
is never invoked.canPop
is set tofalse
, user cannot go back via app bar or back button but againonPopInvoked
is only invoked withdidPop
set tofalse
when pressing app bar back button. It is not invoked for the back gesture.Using GoRouter APIs on Android 14:
canPop
is set totrue
, user can go back via app bar or back button butonPopInvoked
is never invoked.canPop
is set tofalse
, user cannot go back via app bar or back button.onPopInvoked
is invoked in both cases withdidPop
set tofalse
.Summary Table:
NOTE: For clarity, please note that for each column with
onPopInvoked
in the title, thetrue
orfalse
in the rows associated with that column indicate whether or not theonPopInvoked
callback was invoked. This column is NOT intended to indicate anything about thedidPop
value, which is always (AFAIK) correct.canPop
onPopInvoked
(appBar)onPopInvoked
(back swipe)onPopInvoked
(Physical button)Expected results
The component should behave as described in the docs.
Actual results
See the table in the Steps to reproduce section.
Code sample
Code can be found in this repo.
Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
[Paste your logs here]
Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: