-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[go_router] ShellRoute will merge GoRouter's observers #9436
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
Open
huanghui1998hhh
wants to merge
5
commits into
flutter:main
Choose a base branch
from
huanghui1998hhh:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4e87717
[go_router] `ShellRoute` will merge `GoRouter`'s observers
huanghui1998hhh 962c175
fix: test
huanghui1998hhh d954fd5
update CHANGELOG.md and pubspec.yaml
huanghui1998hhh 58f3da2
Merge branch 'main' into main
huanghui1998hhh 1bfdc41
Added `observers` property to `GoRouter` to make it easier to access …
huanghui1998hhh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import 'package:flutter/widgets.dart'; | ||
|
||
/// A [NavigatorObserver] that merges the observers of the current | ||
/// route with the observers of the previous route. | ||
class MergedNavigatorObserver extends NavigatorObserver { | ||
/// Default constructor for the merged navigator observer. | ||
MergedNavigatorObserver(this.observers); | ||
|
||
/// The observers to be merged. | ||
final List<NavigatorObserver> observers; | ||
|
||
@override | ||
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) { | ||
for (final NavigatorObserver observer in observers) { | ||
observer.didPush(route, previousRoute); | ||
} | ||
} | ||
|
||
@override | ||
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) { | ||
for (final NavigatorObserver observer in observers) { | ||
observer.didPop(route, previousRoute); | ||
} | ||
} | ||
|
||
@override | ||
void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) { | ||
for (final NavigatorObserver observer in observers) { | ||
observer.didRemove(route, previousRoute); | ||
} | ||
} | ||
|
||
@override | ||
void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) { | ||
for (final NavigatorObserver observer in observers) { | ||
observer.didReplace(newRoute: newRoute, oldRoute: oldRoute); | ||
} | ||
} | ||
|
||
@override | ||
void didChangeTop(Route<dynamic> topRoute, Route<dynamic>? previousTopRoute) { | ||
for (final NavigatorObserver observer in observers) { | ||
observer.didChangeTop(topRoute, previousTopRoute); | ||
} | ||
} | ||
|
||
@override | ||
void didStartUserGesture( | ||
Route<dynamic> route, Route<dynamic>? previousRoute) { | ||
for (final NavigatorObserver observer in observers) { | ||
observer.didStartUserGesture(route, previousRoute); | ||
} | ||
} | ||
|
||
@override | ||
void didStopUserGesture() { | ||
for (final NavigatorObserver observer in observers) { | ||
observer.didStopUserGesture(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why make this a per route setting instead of a global setting in goRouter?
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 what if it is a shellroute nested inside another shell route, if this is true, should the innershellroute notify the observer of outer shellroute?
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.
Maybe we should use
Navigator.maybeOf(context).widget.observers
to merge observers and keep themergeObservers
property for eachShellRoute
.This ensures that the case of
ShellRoute
nestingShellRoute
is handled correctly, but there is one exception: whenShellRoute
is nested under aNavigator
that is not built byShellRoute
. Maybe we should ignore this case.The reason for adding
mergeObservers
property to eachShellRoute
is to allow users to decide that a specificShellRoute
should not merge observers. Defining it as a global setting inGoRouter
would make maintaining this case difficult.