Add alignment to SizeTransition#177895
Conversation
|
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. |
There was a problem hiding this comment.
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.
| /// 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]. |
There was a problem hiding this comment.
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].There was a problem hiding this comment.
| shadowColor: colorScheme.shadow, | ||
| child: SizeTransition( | ||
| axisAlignment: position.dx < 0 ? 1 : -1, | ||
| alignment: Alignment(-1, position.dx < 0 ? 1 : -1), |
There was a problem hiding this comment.
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.
| alignment: Alignment(-1, position.dx < 0 ? 1 : -1), | |
| alignment: AlignmentDirectional(-1.0, position.dx < 0 ? 1.0 : -1.0), |
There was a problem hiding this comment.
| right: 0.0, | ||
| child: SizeTransition( | ||
| axisAlignment: _isIndicatorAtTop! ? 1.0 : -1.0, | ||
| alignment: Alignment(-1, _isIndicatorAtTop! ? 1.0 : -1.0), |
There was a problem hiding this comment.
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),There was a problem hiding this comment.
| /// The alignment of the child along the main axis during the transition. | ||
| final AlignmentGeometry alignment; |
There was a problem hiding this comment.
This is a breaking change, I'm not sure how we'd want to handle that? Maybe @justinmc has suggestions ?
There was a problem hiding this comment.
There was a problem hiding this comment.
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.
|
Hi @victorsanni @ValentinVignal , thank you for your review. Would it be possible to keep Here's what I'm suggesting:
class SizeTransition extends AnimatedWidget {
@Deprecated('Use alignment instead.')
final double? axisAlignment;
final AlignmentGeometry? alignment;
...
const SizeTransition({
...
}) : assert(axisAlignment == null || alignment == null),
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? |
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 There are other places in the framework with similar concerns, we usually document them in breaking changes that would improve the overall API. |
There was a problem hiding this comment.
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?
|
Hi @Piinks , happy to update the PR 👍 . What do you think of this approach? Here’s what I think is still needed:
Is there an example of how to implement |
|
If this is made backwards compatible, the customer testing likely won't need to be fixed. |
|
Just to confirm, I think we've aligned on how to move forward, right? |
|
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, |
There was a problem hiding this comment.
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.',
)
| @Deprecated('Use alignment instead. ') this.axisAlignment, | |
| @Deprecated('Use alignment instead. ' | |
| 'This feature was deprecated after v3.28.0-3.0.pre.', | |
| ) this.axisAlignment, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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? :)
d2aa4df to
38d821c
Compare
ValentinVignal
left a comment
There was a problem hiding this comment.
LGTM! Thank you for the contribution @IvoneDjaja 🎉
victorsanni
left a comment
There was a problem hiding this comment.
Thanks for the PR. Dart fixing with AlignmentDirectional here is a great idea, and allays my fears of a non-smooth transition for users.
This reverts commit 786ed11.
|
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. |
Remove
axisAlignmentand addalignmentto fix #19850If 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-assistbot 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.