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

[go_router] add current state getter #7651

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

cedvdb
Copy link
Contributor

@cedvdb cedvdb commented Sep 15, 2024

Adds a current state getter that returns GoRouterState.

I've no idea if this is correct but the added tests seem to be passing. Rebuilding the state may be expensive too ?

Fix: flutter/flutter#129833

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@cedvdb cedvdb changed the title [go_router] add current state getter [draft][go_router] add current state getter Sep 15, 2024
@cedvdb cedvdb changed the title [draft][go_router] add current state getter [go_router] add current state getter Sep 15, 2024
@@ -167,6 +168,10 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList>
}());
}

/// The current [GoRouterState]
GoRouterState? get currentState => currentConfiguration.last
.buildState(_configuration, currentConfiguration);
Copy link
Contributor Author

@cedvdb cedvdb Sep 16, 2024

Choose a reason for hiding this comment

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

Is there a way to access the last one without rebuilding the state here ?

Copy link
Contributor

Choose a reason for hiding this comment

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

no unless you caches in the GoRouterStateRegistry, which is something i was planning to do at some point.

but I won't worry too much about this at the moment.

Copy link
Contributor

Choose a reason for hiding this comment

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

also the document should mention what will be returned if you use GoRouter.push()

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

This can also solve flutter/flutter#129833

Edit: nvm you already linked the issue

@@ -167,6 +168,10 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList>
}());
}

/// The current [GoRouterState]
GoRouterState? get currentState => currentConfiguration.last
.buildState(_configuration, currentConfiguration);
Copy link
Contributor

Choose a reason for hiding this comment

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

no unless you caches in the GoRouterStateRegistry, which is something i was planning to do at some point.

but I won't worry too much about this at the moment.

expect(state?.name, 'books');
expect(state?.fullPath, '/books');

router.go('/tulips');
Copy link
Contributor

Choose a reason for hiding this comment

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

can you also do a push /tultips to make sure it can handle imperative shellroute push?

@@ -167,6 +168,10 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList>
}());
}

/// The current [GoRouterState]
GoRouterState? get currentState => currentConfiguration.last
.buildState(_configuration, currentConfiguration);
Copy link
Contributor

Choose a reason for hiding this comment

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

also the document should mention what will be returned if you use GoRouter.push()

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

Successfully merging this pull request may close these issues.

[go_router] Come up with a better way to get the current location without context
2 participants