Skip to content
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

Fixes #1839 #1840

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Fixes #1839 #1840

wants to merge 5 commits into from

Conversation

kane-knowby
Copy link

Proposed fix for #1839

@kane-knowby kane-knowby changed the title fix: Issues combining pop with back, creating a loop. fix: #1839 Jan 18, 2024
@kane-knowby kane-knowby changed the title fix: #1839 Fixes #1839 Jan 18, 2024
@Milad-Akarie
Copy link
Owner

Hey @kane-knowby Thank you for your hard work, I just added some notes, please share your thoughts.

@kane-knowby
Copy link
Author

Hey @kane-knowby Thank you for your hard work, I just added some notes, please share your thoughts.

Hey thanks for taking a look! Unfortunately I can't see any notes/comments, were they on the PR or somewhere else?

@Milad-Akarie
Copy link
Owner

Milad-Akarie commented Mar 29, 2024

Hey @kane-knowby my bad, forgot to commit them

Copy link
Owner

@Milad-Akarie Milad-Akarie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added reviews

@override
@optionalTypeArgs
Future<bool> pop<T extends Object?>([T? result]) async {
final NavigatorState? navigator = _navigatorKey.currentState;
if (navigator == null) return SynchronousFuture<bool>(false);
if (await navigator.maybePop<T>(result)) {
// On the web, popping will not update the navigation history
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might introduce hard-to-trace breaking changes for some users, I suggest we flag it, users who require this behavior will pass some flag (e.g useBackForPopOnWeb, 'maybe shorter') to the root router, or maybe override one.

/// Get the top [Route<dynamic>] of Navigator
/// Used to assess the current route and popDisposition
Route<dynamic> get _navigatorTopRoute {
late Route<dynamic> route;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we rely on pagelessRoutesObserver.current instead of using popUntil?

@@ -20,6 +20,12 @@ class NavigationHistoryImpl extends NavigationHistory {
void onNewUrlState(UrlState newState, {bool notify = true}) {
super.onNewUrlState(newState, notify: notify);
if (_currentUrl == newState.url) return;
// If the previous url is the same as the new url
// then we can infer that the screen was popped and remove the last entry
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should explicitly remove the last entry inside onPopPage ( just added the method to StackRouter) instead of assuming the entry is a result of the pop event, can't think of a particular reason why the current setup might not work in some cases but, I have my doubts, in the browser history you can have the same url added multiple times with different states, we might have a similar implementation in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants