Commit d43b4d0a authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by Greg Spencer

Fix #16247: SizeTransition clamps negative size factors (#16579)

As pointed out in the bug, the issue is fixed by just clamping sizeFactor.value.

Fixes #16247 
parent a043ac41
......@@ -290,8 +290,8 @@ class SizeTransition extends AnimatedWidget {
return new ClipRect(
child: new Align(
alignment: alignment,
heightFactor: axis == Axis.vertical ? sizeFactor.value : null,
widthFactor: axis == Axis.horizontal ? sizeFactor.value : null,
heightFactor: axis == Axis.vertical ? math.max(sizeFactor.value, 0.0) : null,
widthFactor: axis == Axis.horizontal ? math.max(sizeFactor.value, 0.0) : null,
child: child,
)
);
......
......@@ -191,4 +191,66 @@ void main() {
expect(actualAlign.widthFactor, 0.3);
expect(actualAlign.heightFactor, 0.4);
});
testWidgets('SizeTransition clamps negative size factors - vertical axis', (WidgetTester tester) async {
final AnimationController controller = new AnimationController(vsync: const TestVSync());
final Animation<double> animation = new Tween<double>(begin: -1.0, end: 1.0).animate(controller);
final Widget widget = new Directionality(
textDirection: TextDirection.ltr,
child: new SizeTransition(
axis: Axis.vertical,
sizeFactor: animation,
child: const Text('Ready'),
),
);
await tester.pumpWidget(widget);
final RenderPositionedBox actualPositionedBox = tester.renderObject(find.byType(Align));
expect(actualPositionedBox.heightFactor, 0.0);
controller.value = 0.0;
await tester.pump();
expect(actualPositionedBox.heightFactor, 0.0);
controller.value = 0.75;
await tester.pump();
expect(actualPositionedBox.heightFactor, 0.5);
controller.value = 1.0;
await tester.pump();
expect(actualPositionedBox.heightFactor, 1.0);
});
testWidgets('SizeTransition clamps negative size factors - horizontal axis', (WidgetTester tester) async {
final AnimationController controller = new AnimationController(vsync: const TestVSync());
final Animation<double> animation = new Tween<double>(begin: -1.0, end: 1.0).animate(controller);
final Widget widget = new Directionality(
textDirection: TextDirection.ltr,
child: new SizeTransition(
axis: Axis.horizontal,
sizeFactor: animation,
child: const Text('Ready'),
),
);
await tester.pumpWidget(widget);
final RenderPositionedBox actualPositionedBox = tester.renderObject(find.byType(Align));
expect(actualPositionedBox.widthFactor, 0.0);
controller.value = 0.0;
await tester.pump();
expect(actualPositionedBox.widthFactor, 0.0);
controller.value = 0.75;
await tester.pump();
expect(actualPositionedBox.widthFactor, 0.5);
controller.value = 1.0;
await tester.pump();
expect(actualPositionedBox.widthFactor, 1.0);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment