Skip to content

Add alignment to SizeTransition#177895

Merged
auto-submit[bot] merged 21 commits intoflutter:masterfrom
IvoneDjaja:size-transition/alignment
Jan 26, 2026
Merged

Add alignment to SizeTransition#177895
auto-submit[bot] merged 21 commits intoflutter:masterfrom
IvoneDjaja:size-transition/alignment

Conversation

@IvoneDjaja
Copy link
Contributor

@IvoneDjaja IvoneDjaja commented Nov 2, 2025

Remove axisAlignment and add alignment to fix #19850

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

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

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@google-cla
Copy link

google-cla bot commented Nov 2, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos labels Nov 2, 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 SizeTransition to replace the axisAlignment property with a more flexible alignment property. This is a breaking change that gives developers more control over the child's alignment. The changes across the codebase have been updated to use the new alignment property. My feedback focuses on improving the documentation for the new alignment property to accurately reflect its behavior and ensuring that text-direction awareness is preserved in widgets that were updated to use the new API by using AlignmentDirectional where appropriate.

Comment on lines +415 to +416
/// height, depending upon the value of [axis]. The alignment of the child along
/// the [axis] is specified by the [axisAlignment].
/// the [axis] is specified by the [alignment].
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The documentation here is a bit misleading. It says "The alignment of the child along the [axis] is specified by the [alignment]". However, alignment controls the alignment on both axes, not just the main one defined by axis. It would be clearer to say something like "The alignment of the child is specified by the [alignment]".

/// height, depending upon the value of [axis]. The alignment of the child
/// is specified by the [alignment].

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

shadowColor: colorScheme.shadow,
child: SizeTransition(
axisAlignment: position.dx < 0 ? 1 : -1,
alignment: Alignment(-1, position.dx < 0 ? 1 : -1),
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The previous implementation used axisAlignment, which SizeTransition internally converted to an AlignmentDirectional. This made it sensitive to the text direction (LTR/RTL). By changing to Alignment, this directionality is lost. To preserve the original behavior, you should use AlignmentDirectional here.

Suggested change
alignment: Alignment(-1, position.dx < 0 ? 1 : -1),
alignment: AlignmentDirectional(-1.0, position.dx < 0 ? 1.0 : -1.0),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right: 0.0,
child: SizeTransition(
axisAlignment: _isIndicatorAtTop! ? 1.0 : -1.0,
alignment: Alignment(-1, _isIndicatorAtTop! ? 1.0 : -1.0),
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The previous implementation used axisAlignment, which SizeTransition internally converted to an AlignmentDirectional. This made it sensitive to the text direction (LTR/RTL). By changing to Alignment, this directionality is lost. Since RefreshIndicator should respect text direction, it's better to use AlignmentDirectional to preserve the original behavior.

              alignment: AlignmentDirectional(-1.0, _isIndicatorAtTop! ? 1.0 : -1.0),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +475 to +476
/// The alignment of the child along the main axis during the transition.
final AlignmentGeometry alignment;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a breaking change, I'm not sure how we'd want to handle that? Maybe @justinmc has suggestions ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@victorsanni victorsanni left a comment

Choose a reason for hiding this comment

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

Hi @IvoneDjaja, thanks for the noble effort. However, this is a severely breaking change for any current users of SizeTransition.axisAlignment.

Normally, in these situations, I recommend using dart fix to automatically migrate users. However, here the transformation will be complex because this is a migration from a double to an Alignment. It is theoretically possible to use SizeTransition.axis to figure out how to create an Alignment object (e.g if axis is Axis.vertical and axisAlignment is 1.0, then use Alignment(0.0, 1.0)). But I can't say how doable that is with dart fix.

Overall, while this will lead to a better API, I don't think this is reason enough to break users. IMO the linked issue should be appended to breaking changes that would improve the overall API.

@IvoneDjaja
Copy link
Contributor Author

IvoneDjaja commented Nov 4, 2025

Hi @victorsanni @ValentinVignal , thank you for your review.

Would it be possible to keep axisAlignment as deprecated while adding the new alignment parameter? This would provide a smooth migration path for existing users while offering a better API for new ones.

Here's what I'm suggesting:

  1. Keep both parameters nullable with an assertion to ensure exactly one is provided:
class SizeTransition extends AnimatedWidget {
  @Deprecated('Use alignment instead.')
  final double? axisAlignment;
  final AlignmentGeometry? alignment;
  ...

  const SizeTransition({
    ...
  }) : assert(axisAlignment == null || alignment == null),
  1. Update the build method to prioritize alignment when available:
Widget build(BuildContext context) {
    return ClipRect(
      child: Align(
        alignment: alignment ?? switch (axis) {
          Axis.horizontal => AlignmentDirectional(axisAlignment, -1.0),
          Axis.vertical => AlignmentDirectional(-1.0, axisAlignment),
        },
        ...

What are your thoughts on this approach?

@victorsanni
Copy link
Contributor

Would it be possible to keep axisAlignment as deprecated while adding the new alignment parameter? This would provide a smooth migration path for existing users while offering a better API for new ones.

I'm not sure deprecating a property without a dart fix is a 'smooth' migration. Users will have to manually update their code to adopt the new API, which will require them to re-familiarize themselves with Alignment and SizeTransition APIs, introducing cognitive load. And this cognitive load seems unnecessary given this API doesn't add any new features or behaviors.

There are other places in the framework with similar concerns, we usually document them in breaking changes that would improve the overall API.

@dkwingsmt dkwingsmt requested review from Piinks and dkwingsmt November 5, 2025 19:21
Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

Hey @IvoneDjaja thanks for contributing! As this is currently proposed, this would be a pretty big breaking change. Usually we introduce the new property, deprecate the old one, and maintain backwards compatibility while the old property is deprecated with a dart fix to help folks migrate. Would you be able to update this PR to do that?

@IvoneDjaja
Copy link
Contributor Author

IvoneDjaja commented Nov 6, 2025

Hi @Piinks , happy to update the PR 👍 . What do you think of this approach?

Here’s what I think is still needed:

  1. Fix the failing test Linux customer_testing
  2. Fix the failing test Mac customer_testing
  3. Add deprecation with dart fix

Is there an example of how to implement 3. Add deprecation with dart fix?
Please let me know if I’m missing anything.

@IvoneDjaja IvoneDjaja requested a review from Piinks November 6, 2025 11:31
@Piinks
Copy link
Contributor

Piinks commented Nov 6, 2025

If this is made backwards compatible, the customer testing likely won't need to be fixed.
Here is one PR where something was deprecated as an example: #161295
Docs on dart fix: https://github.com/flutter/flutter/blob/master/docs/contributing/Data-driven-Fixes.md

@dkwingsmt
Copy link
Contributor

Just to confirm, I think we've aligned on how to move forward, right?

@github-actions github-actions bot added the c: tech-debt Technical debt, code quality, testing, etc. label Nov 20, 2025
@IvoneDjaja
Copy link
Contributor Author

Hi @Piinks and @dkwingsmt, I’ve updated the PR. Please let me know your thoughts.

this.axis = Axis.vertical,
required Animation<double> sizeFactor,
this.axisAlignment = 0.0,
@Deprecated('Use alignment instead. ') this.axisAlignment,
Copy link
Contributor Author

@IvoneDjaja IvoneDjaja Nov 20, 2025

Choose a reason for hiding this comment

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

Hi @Piinks, I noticed the deprecation message This feature was deprecated after v3.28.0-3.0.pre. in the referenced PR. Should we include a similar message in this PR as well? If so, what version should we use? I’ll also update the other deprecated annotations accordingly.

 @Deprecated(
    'Use minimumSize instead. '
    'This feature was deprecated after v3.28.0-3.0.pre.',
  )
Suggested change
@Deprecated('Use alignment instead. ') this.axisAlignment,
@Deprecated('Use alignment instead. '
'This feature was deprecated after v3.28.0-3.0.pre.',
) this.axisAlignment,

Copy link
Contributor

Choose a reason for hiding this comment

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

Deprecation format is actually enforced, which is why the analyzer is failing. :)
If you rebase and run flutter doctor, that is the version you would use. Docs: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#deprecations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @Piinks, I accidentally rebased on an outdated main, so I had to rebase again and force‐push twice. Could you check this version and let me know if everything looks correct now? :)

Fix deprecation message

@IvoneDjaja IvoneDjaja force-pushed the size-transition/alignment branch from d2aa4df to 38d821c Compare November 22, 2025 01:04
@github-actions github-actions bot added a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems platform-android Android applications specifically labels Nov 22, 2025
Copy link
Contributor

@ValentinVignal ValentinVignal left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for the contribution @IvoneDjaja 🎉

Copy link
Contributor

@victorsanni victorsanni left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Dart fixing with AlignmentDirectional here is a great idea, and allays my fears of a non-smooth transition for users.

@auto-submit
Copy link
Contributor

auto-submit bot commented Jan 26, 2026

autosubmit label was removed for flutter/flutter/177895, because - The status or check suite Windows tool_integration_tests_2_9 has failed. Please fix the issues identified (or deflake) before re-applying this label.

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

Labels

c: tech-debt Technical debt, code quality, testing, etc. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos 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.

SizeTransition hard codes cross axis alignment.

6 participants