Skip to content

[go_router] [shell_route] Add observers parameter - #2664

Merged
auto-submit[bot] merged 12 commits into
flutter:mainfrom
angjelkom:shell-route-observers
Feb 14, 2023
Merged

[go_router] [shell_route] Add observers parameter#2664
auto-submit[bot] merged 12 commits into
flutter:mainfrom
angjelkom:shell-route-observers

Conversation

@angjelkom

@angjelkomangjelkom commented Sep 30, 2022

Copy link
Copy Markdown
Contributor

This PR adds observers parameter to the ShellRoute and passes that to the nested Navigator created by that same ShellRoute.

The need for this PR is because it fixes cases where a Hero animation doesn't work when used with nested navigation and it requires a HeroController to be used as an observer for that nested Navigator.

fixesflutter/flutter#112095

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

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

@flutter-dashboard

Copy link
Copy Markdown

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 on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@grimatomagrimatoma left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@chunhtai
chunhtai self-requested a review October 13, 2022 21:46
Comment threadpackages/go_router/lib/src/builder.dart Outdated
@chunhtai

Copy link
Copy Markdown
Contributor

Hi @angjelkom , are you still planning to work on this pr?

@angjelkom

angjelkom commented Nov 11, 2022

Copy link
Copy Markdown
ContributorAuthor

Hi @angjelkom , are you still planning to work on this pr?

Apologize, yes I will add your suggested change over the weeekend. I've been busy with work.

@angjelkom

Copy link
Copy Markdown
ContributorAuthor

@chunhtai I will need a bit more time, as merging the latest commits from the main branch caused my example to have weird side-effects where the Hero animation doesn't work when going to the next page but when going back it works in a buggy-weird way.

So until i solve that I can't commit the change for HeroControllerScope.

@chunhtai

Copy link
Copy Markdown
Contributor

@angjelkom are still planning on coming back to this pr?

@angjelkom

Copy link
Copy Markdown
ContributorAuthor

@chunhtai Sorry I am too busy at the moment with work, I will for sure complete it by the end of next week!

@angjelkom

Copy link
Copy Markdown
ContributorAuthor

@chunhtai I can't complete the pull request until #115832 its fixed, its blocking me.

I could use a lower commit but still I would need to test it against the latest commit at the end and currently that's not possible because of the above issue.

@chunhtai

Copy link
Copy Markdown
Contributor

@angjelkom I will take a look at the issue and try to resolve it asap

@ycherniavskyi

Copy link
Copy Markdown
Contributor

@angjelkom, the issue you mentioned has been fixed. Could you update your PR for merging? If you are too busy, I could create an analogic PR. I need it solely for FirebaseAnalyticsObserver.

@angjelkom

Copy link
Copy Markdown
ContributorAuthor

@ycherniavskyi yes saw the merge today, I will proceed with completing the PR

@angjelkom
angjelkomforce-pushed the shell-route-observers branch 4 times, most recently from 4b28692 to f11123dCompareDecember 8, 2022 19:31
@angjelkom

Copy link
Copy Markdown
ContributorAuthor

@ycherniavskyi the PR is ready waiting for @chunhtai to review it and approve it.

Comment threadpackages/go_router/lib/src/route.dart Outdated
Comment threadpackages/go_router/lib/src/builder.dart Outdated
@angjelkom
angjelkomforce-pushed the shell-route-observers branch from f11123d to 915f6b2CompareDecember 9, 2022 08:01
@arsen

Copy link
Copy Markdown

any chance this will get merged soon?

@angjelkom

Copy link
Copy Markdown
ContributorAuthor

@arsen I will get on it tonight to finish it up.

@angjelkom

Copy link
Copy Markdown
ContributorAuthor

@chunhtai as @ycherniavskyi suggested we should use the relevant HeroController based on whether MaterialApp or CupertinoApp is used, in order to do that we need to use the RouteBuilder not the ShellRoute in order to access the context.

The issue is because the RouteBuilder gets rebuild while navigating the HeroController which again breaks the animation, the way I see it we have two options:

Option 1:

Create 3 final variables in the RouteBuilder, one using createMaterialHeroController, one using createCupertinoHeroController and a default HeroController.
Then we can use those to pass the correct controller.
This way the controllers won't be rebuild and the animation would work. (tested)

Option 2:

Have a heroController parameter to the ShellRoute so that the user passes one himself.

Let me know what would you recommend, I can do the change tonight.

@chunhtai

Copy link
Copy Markdown
Contributor

Hi @angjelkom, it looks like @flodaniel has provided a test, can you commit to this pr so that i can merge it?

@angjelkom

Copy link
Copy Markdown
ContributorAuthor

@flodaniel Thanks a lot for the test! @chunhtai merged it, but at the moment submit-queue check is failing for some other reason.

@hannah-hyjhannah-hyj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@lublot

Copy link
Copy Markdown

Hello everyone! Is there any prediction of when it will be merged?

@chunhtaichunhtai added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 14, 2023
@auto-submit
auto-submitBot merged commit 278b489 into flutter:mainFeb 14, 2023
auto-submitBot pushed a commit that referenced this pull request Dec 7, 2023
…ng a `ShellRoute` with `observers` (#5563)
[This pr](#2664) added the ability to provide a list of `NavigatorObservers` to a `ShellRoute`. The equivalent was never added to `go_router_builder`, so this pr provides that functionality.
This is a workaround to [this issue](flutter/flutter#112196) where navigator observers added to a `GoRouter` at the top level do not fire in `ShellRoutes`. With this change, you can provide `NavigatorObservers` directly to the `ShellRoute`
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
* [go_router] [shell_route] Add observers parameter
* [go_router] [shell_route] Add observers parameter test
* Added Licence for shell_route_observers_test.dart
* [go_router] [shell_route] Added type annotation to shell_route_observers_test.dart
* [go_router] [shell_route] Use `HeroControllerScope` for nested Navigator
* Use the correct HeroController based on the App type.
* Cache the HeroController for the nested Navigator.
* Clean up previous cache to prevent memory leak.
* Added better cache-clearing policy for the HeroController cache.
* Fixed Typos
Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com>
* Fixed Typos
Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com>
* [go_router] [shell_route] Added a better Hero test
Credits to @flodaniel!
---------
Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com>
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…ng a `ShellRoute` with `observers` (flutter#5563)
[This pr](flutter#2664) added the ability to provide a list of `NavigatorObservers` to a `ShellRoute`. The equivalent was never added to `go_router_builder`, so this pr provides that functionality.
This is a workaround to [this issue](flutter/flutter#112196) where navigator observers added to a `GoRouter` at the top level do not fire in `ShellRoutes`. With this change, you can provide `NavigatorObservers` directly to the `ShellRoute`
bisor0627 pushed a commit to bisor0627/packages that referenced this pull request Jun 19, 2026
* [go_router] [shell_route] Add observers parameter
* [go_router] [shell_route] Add observers parameter test
* Added Licence for shell_route_observers_test.dart
* [go_router] [shell_route] Added type annotation to shell_route_observers_test.dart
* [go_router] [shell_route] Use `HeroControllerScope` for nested Navigator
* Use the correct HeroController based on the App type.
* Cache the HeroController for the nested Navigator.
* Clean up previous cache to prevent memory leak.
* Added better cache-clearing policy for the HeroController cache.
* Fixed Typos
Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com>
* Fixed Typos
Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com>
* [go_router] [shell_route] Added a better Hero test
Credits to @flodaniel!
---------
Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com>
bisor0627 pushed a commit to bisor0627/packages that referenced this pull request Jun 19, 2026
…ng a `ShellRoute` with `observers` (flutter#5563)
[This pr](flutter#2664) added the ability to provide a list of `NavigatorObservers` to a `ShellRoute`. The equivalent was never added to `go_router_builder`, so this pr provides that functionality.
This is a workaround to [this issue](flutter/flutter#112196) where navigator observers added to a `GoRouter` at the top level do not fire in `ShellRoutes`. With this change, you can provide `NavigatorObservers` directly to the `ShellRoute`
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmitMerge PR when tree becomes green via auto submit Appneeds testsp: go_router

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[go_router] Hero animation don't work between pages nested on ShellRoute

14 participants

@angjelkom@chunhtai@ycherniavskyi@arsen@matecode@VusDanylo@jonasbark@ahmednfwela@kamami@lublot@grimatoma@flodaniel@thipokch@hannah-hyj