-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
base: main
Are you sure you want to change the base?
Conversation
@@ -167,6 +168,10 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList> | |||
}()); | |||
} | |||
|
|||
/// The current [GoRouterState] | |||
GoRouterState? get currentState => currentConfiguration.last | |||
.buildState(_configuration, currentConfiguration); |
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.
Is there a way to access the last one without rebuilding the state here ?
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.
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.
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.
also the document should mention what will be returned if you use GoRouter.push()
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.
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); |
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.
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'); |
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.
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); |
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.
also the document should mention what will be returned if you use GoRouter.push()
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
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or this PR is exempt from CHANGELOG changes.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.