-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Navigator: Refactor the imperative api to continue working in the new navigation system #44930
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
ab28a6e
to
d248ddd
Compare
9aa90a4
to
4bef7fa
Compare
4bef7fa
to
9e50db3
Compare
9e50db3
to
cb32951
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Will continue review after lunch)
// \ / | ||
// idle--------+ | ||
// / \ | ||
// / \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: When we support pages, we probably also need a seperate "complete" state, see https://docs.google.com/document/d/1Q0jx0l4-xymph9O6zLaOY4d_f7YFpNWX_eGbzYxr9wY/edit#heading=h.5im0pq8myoqk
When you address the changes to this PR can you please push a separate commit for those changes to make it easier to review them? Thanks! |
dce6bd8
to
e99d5d4
Compare
b9a64f6
to
4545840
Compare
c4d618f
to
b879caf
Compare
d10c582
to
f995f6a
Compare
@goderbauer This is ready to review, please the the most recent commit. I also include a breaking change email draft. https://docs.google.com/document/d/16T1FCpfP7y2nPAg4PHcQBaXTNZaF3oQjPZJkcnsaKMI/edit# |
f995f6a
to
c595650
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -290,6 +302,17 @@ class WidgetsApp extends StatefulWidget { | |||
/// default handler will know what routes and [PageRoute]s to build. | |||
final RouteFactory onGenerateRoute; | |||
|
|||
/// {@template flutter.widgets.widgetsApp.onGenerateInitialRoutes} | |||
/// The routes generator callback used for generating initial routes if | |||
/// [initialRoute] is provided |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: end with a .
/// If this property is not set, the underlying | ||
/// [Navigator.onGenerateInitialRoutes] will default to | ||
/// [Navigator.defaultGenerateInitialRoutes]. | ||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove this blank line.
@chunhtai I have just been tracking down a bug caused by this PR. I understood from the breaking change notice. You have deprecated the @override
AnimationController createAnimationController() {
final AnimationController controller = super.createAnimationController();
if (settings.isInitialRoute)
controller.value = 1.0;
return controller;
} It is quite vital to be able to stop that initial animation when you for instance use the following code snippet to replace the entire stack with a new root route. Navigator.of(context).pushAndRemoveUntil(route, (_) => false); I bring this to your attention to perhaps discuss resolution. In terms of either add the function back in until the flag itself is removed. Or, create a new breaking-change notice announcing this feature removal and adding the function in your own routes as a resolution until the Navigator 2.0 work is complete? |
@slightfoot Back to your question, to achieve the same result without transition, you can use replace to replace the top most route, and use remoteRoute or removeRouteBelow to remove the route below. The problem with this approach is you have to have the reference of the route in current history, you might need to keep track of them yourself which is a bit cumbersome. The use case you demonstrate here is actually the reason why we want to do the refactoring and page api. Let me know if you have any questions or concerns. |
@chunhtai as you can see the current implementation of the Navigator does not allow for an alternative to a clear and replace stack. Even if this is a bug-fix, how do we achieve this same behaviour with the new API. You can't remove the isInitialRoute breaking many apps without a replacement feature or migration guide. and the current Migration guide does not cover this scenario. |
@chunhtai I also use this way of resetting the stack. Actually it's very popular on Stack Overflow whenever anyone asks how to do it e.g. here. In my opinion even though you consider this a bug, many people rely on this behavior. I've heard this solution being recommended on meetups as the "proper one". |
@orestesgaolin it is ok to rely on this to reset the stack, but it should come with pushing animation. |
@chunhtai yeah, it seems that the names implies the animation. However, I think it should be widely announced that such change in behavior can occur. |
@orestesgaolin I can add a follow up announcement to the original breaking change, but there is current no migration guide if you want to pushAndRemoveUntil without animation. |
@chunhtai I think if the problem was only the name, what about creating another method with the same functionality but without animations |
@jsnoriegam That is what i would do if we don't plan to rewrite the whole routing api. However, it does not make sense to extend the imperative api if we plan to encourage people to move to a new system. |
Description
This is based on https://github.com/flutter/flutter/pull/30211/files
is the first part of
#45938
[breaking change]
https://groups.google.com/g/flutter-dev/c/A9JSQojOt6I/m/DxCS9eV0GwAJ
Tests
I added the following tests:
Existing test suit should cover the most
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?