Skip to content

Refactor: Migrate page transition builder to widgets #174090

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rkishan516
Copy link
Contributor

@rkishan516 rkishan516 commented Aug 20, 2025

Changes:

  • Move PageTransitionsBuilder and its implementation classes like FadeUpwardsPageTransitionsBuilder, OpenUpwardsPageTransitionsBuilder, FadeForwardsPageTransitionsBuilder, ZoomPageTransitionsBuilder, CupertinoPageTransitionsBuilder to widgets
  • Move PredictiveBackPageTransitionsBuilder to widgets

part of: #172929

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 [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • 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].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

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.If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Aug 20, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors several page transition related classes, moving them from the material library to the widgets library. This is a good step towards better code organization. My main feedback is regarding a layering violation introduced by the move, where the new files in the widgets library still have dependencies on the material library. I've left a specific comment on how to address this.

Comment on lines 17 to 18
import '../material/color_scheme.dart';
import '../material/theme.dart';
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This file has been moved to the widgets library, but it still has dependencies on the material library. The widgets library is a lower-level package than material and should not depend on it. These imports introduce a layering violation.

To resolve this, consider removing the dependency on Theme and ColorScheme by passing the required values (like backgroundColor) down from the material layer where these builders are used, instead of looking them up from the context here.

@rkishan516
Copy link
Contributor Author

Current implementation still contains

import '../material/color_scheme.dart';
import '../material/theme.dart';

as import in page_transition_theme.dart.

@victorsanni
Copy link
Contributor

Current implementation still contains

import '../material/color_scheme.dart';
import '../material/theme.dart';

as import in page_transition_theme.dart.

widgets/ can't import material/, so this can't be a straightforward move to widgets/. I think the transition builders aren't tied to material/, but the page transitions theme (and any other theming stuff) probably is, so should remain.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

I appreciate you jumping on this @rkishan516!

+1 to what @victorsanni said: #174090 (comment)

I just wanted to chime in to say that I'm exploring adding a widgets/system_ui directory for this kind of stuff. Depending on if or what you are able to move out of Material, that might be the long term destination for it.

@rkishan516
Copy link
Contributor Author

widgets/ can't import material/, so this can't be a straightforward move to widgets/. I think the transition builders aren't tied to material/, but the page transitions theme (and any other theming stuff) probably is, so should remain.

Actually @victorsanni, Its both PageTransitionBuilder and PageTransitionTheme that depends on MaterialTheme right now.

I just wanted to chime in to say that I'm exploring adding a widgets/system_ui directory for this kind of stuff. Depending on if or what you are able to move out of Material, that might be the long term destination for it.

Sure @justinmc, I can keep this MR on hold until system_ui is created.

@MitchellGoodwin
Copy link
Contributor

Its both PageTransitionBuilder and PageTransitionTheme that depends on MaterialTheme right now.

It's a hard requirement that the Widgets library can't import Material or Cupertino, or else it creates a circular dependency. I do not think there is a way to move PageTransitionTheme down without causing issues right now, so that should stay in Material. Ongoing investigations are happening around theming options in the Widget layer and that may provide a way to do that later.

So what should move down is PageTransitionsBuilder and the classes that extend from it. That still leaves the dependency on Theme and ColorScheme. Both are used to get a default background color for the transitions that need it. That gets partially resolved by adding a backgroundColor property to two of the builders. I suggest moving the backgroundColor property to PageTransitionBuilder so it can be used by all extended classes, and removing the theme look up from the builders. Then PageTransitionTheme, which is still in Material can see if backgroundColor is null and if so, it can set the backgroundColor using the Material theme.

Also the Cupertino transition builder will need the relevant code from Cupertino to move down as well.

@rkishan516 rkishan516 force-pushed the migrate-transition-builder branch from b5ffd93 to 2e6a8ea Compare August 22, 2025 02:14
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

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. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@rkishan516 rkishan516 force-pushed the migrate-transition-builder branch from 2e6a8ea to 98a9ced Compare August 22, 2025 02:23
@rkishan516
Copy link
Contributor Author

@MitchellGoodwin I have updated PR based on your suggestion, but when backgroundColor is not given in PageTransitionBuilder, I had to fallback to transparent.
Instances where transparent was used :-

  1. FadeForwardsPageTransitionsBuilder.delegatedTransition
  2. FadeForwardsPageTransitionsBuilder.buildTransitions
  3. ZoomPageTransitionsBuilder.delegatedTransition
  4. ZoomPageTransitionsBuilder.buildTransitions

@victorsanni
Copy link
Contributor

Hi @rkishan516, can you draft this PR and open separate PRs migrating these builders individually? Will make it much easier to review.

@rkishan516
Copy link
Contributor Author

Sure @victorsanni, Will do.

@rkishan516 rkishan516 marked this pull request as draft August 22, 2025 07:31
@flutter-dashboard
Copy link

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

For more guidance, visit Writing a golden file test for package:flutter.

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

@rkishan516
Copy link
Contributor Author

@victorsanni, 1st PR for migrate through breaking this PR.
#174321

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants