-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Add SizeTransition.fixedCrossAxisSizeFactor
#134659
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
Add SizeTransition.fixedCrossAxisSizeFactor
#134659
Conversation
|
I'm not too proud of the test. Do you have any idea how I could improve it? |
|
@Renzo-Olivares is there something I should do for this PR? |
Renzo-Olivares
left a comment
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.
Hi @ValentinVignal thanks for the contribution! This looks awesome, I just had a few comments and suggestions for the test.
| expect(actualPositionedBox.widthFactor, 2.0); | ||
| }); | ||
|
|
||
|
|
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.
nit: this extra line is not needed.
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.
Oops, I got it removed in test: Test the size transition cross axis size
| /// | ||
| /// If the value of [crossAxisSizeFactor] is less than one, the child will be | ||
| /// clipped in the appropriate axis. | ||
| final double? crossAxisSizeFactor; |
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 add a comment describing the default behavior when this is not defined. (The cross axis size is as large as the parent).
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.
I added a comment in chore: Add assert and comment. Is that good enough?
| /// | ||
| /// If the value of [crossAxisSizeFactor] is less than one, the child will be | ||
| /// clipped in the appropriate axis. | ||
| final double? crossAxisSizeFactor; |
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.
I wonder if this should have a different name since it is not directly the counter of sizeFactor since it is not an animation.
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.
Sure! I'm all in for a different name, I wasn't really happy with this one. Would you have a suggestion?
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 staticCrossAxisSizeFactor or fixedCrossAxisSizeFactor? I think its important to make it clear that the widget does not listen to this value and animate on it unlike sizeFactor.
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.
I decided to go with fixedCrossAxisSizeFactor and I renamed it in refactor: Rename parameter to fixedCrossAxisSizeFactor
| textDirection: TextDirection.ltr, | ||
| child: SizeTransition( | ||
| sizeFactor: animation, | ||
| crossAxisSizeFactor: 2.0, |
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.
This test works to verify that the crossAxisSizeFactor is actually being passed but we should also add a test that verifies the intended behavior. Maybe that test could verify the size of the parent before/after the transition when crossAxisSizeFactor is set to 1.0. Before the size would be equal to the size of the child, and after it would be 0.
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.
Sure! Nice idea! I added the test in test: Test the size transition cross axis size
| this.axis = Axis.vertical, | ||
| required Animation<double> sizeFactor, | ||
| this.axisAlignment = 0.0, | ||
| this.crossAxisSizeFactor, |
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.
we should probably assert this value is non-negative since Align cannot take a non-negative size factor.
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.
I copied the Align's assert in chore: Add assert and comment
…-with-size-transition # Conflicts: # packages/flutter/test/widgets/transitions_test.dart
| expect(actualPositionedBox.heightFactor, 1.0); | ||
| }); | ||
|
|
||
| testWidgetsWithLeakTracking('SizeTransition with crossAxisSizeFactor should size its cross axi from its children - vertical axis', (WidgetTester tester) async { |
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.
axi -> axis. Same for horizontal test.
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.
Oops sorry about that. I fixed it in doc: Fix typo in test description
Renzo-Olivares
left a comment
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.
Left some comments. Thanks for making the changes!
| await tester.pump(); | ||
| expect(actualPositionedBox.heightFactor, 0.0); | ||
| expect(actualPositionedBox.widthFactor, 1.0); | ||
| expect(tester.getSize(find.byKey(key)), const Size(100, 0)); |
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.
I think there is an extra space in Size(100, 0).
| await tester.pump(); | ||
| expect(actualPositionedBox.heightFactor, 0.0); | ||
| expect(actualPositionedBox.widthFactor, 1.0); | ||
| expect(tester.getSize(find.byKey(key)), const Size(100, 0)); |
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.
Should remove this extra space here (100, 0).
| await tester.pump(); | ||
| expect(actualPositionedBox.heightFactor, 1.0); | ||
| expect(actualPositionedBox.widthFactor, 0.0); | ||
| expect(tester.getSize(find.byKey(key)), const Size(0, 100)); |
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.
nit: remove extra space.
| expect(tester.getSize(find.byKey(key)), const Size(100, 0)); | ||
| }); | ||
|
|
||
| testWidgetsWithLeakTracking('SizeTransition with crossAxisSizeFactor should size its cross axis from its children - horizontal axis', (WidgetTester tester) async { |
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.
nit: update name of crossAxisSizeFactor in tests.
…ossAxisSizeFactor
|
Oops sorry for those mistakes @Renzo-Olivares . I have fixed them in test: Better format the code and rename test description with fixedCr… |
Renzo-Olivares
left a comment
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.
LGTM thank you for the contribution!
SizeTransition.crossAxisSizeFactor SizeTransition.fixedCrossAxisSizeFactor
…-with-size-transition
Fixes #134654
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.