mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

Add a AnimatedRelativeRectValue class for animating RelativeRects. Add a PositionedTransition class for animating Positioned using AnimatedRelativeRectValues. Add a test for PositionedTransition. Fix a math bug a RelativeRect found by the test. Fix a logic bug in the two ParentDataWidget classes found by the test. Specifically, they were marking the child dirty, rather than the parent. The parentData is for the parent's layout, not the child's, so they have to mark the parent dirty. (I didn't hoist this up to the superclass because ParentData could be used for painting, hit testing, accessibility, or any number of other things, and I didn't want to bake in the assumption that it needed markNeedsLayout.)
75 lines
2.3 KiB
Dart
75 lines
2.3 KiB
Dart
import 'package:flutter/animation.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'widget_tester.dart';
|
|
|
|
void main() {
|
|
|
|
test('Can animate position data', () {
|
|
testWidgets((WidgetTester tester) {
|
|
|
|
final AnimatedRelativeRectValue rect = new AnimatedRelativeRectValue(
|
|
new RelativeRect.fromRect(
|
|
new Rect.fromLTRB(10.0, 20.0, 20.0, 30.0),
|
|
new Rect.fromLTRB(0.0, 10.0, 100.0, 110.0)
|
|
),
|
|
end: new RelativeRect.fromRect(
|
|
new Rect.fromLTRB(80.0, 90.0, 90.0, 100.0),
|
|
new Rect.fromLTRB(0.0, 10.0, 100.0, 110.0)
|
|
),
|
|
curve: linear
|
|
);
|
|
final Performance performance = new Performance(
|
|
duration: const Duration(seconds: 10)
|
|
);
|
|
final List<Size> sizes = <Size>[];
|
|
final List<Point> positions = <Point>[];
|
|
final GlobalKey key = new GlobalKey();
|
|
|
|
void recordMetrics() {
|
|
RenderBox box = key.currentContext.findRenderObject();
|
|
BoxParentData boxParentData = box.parentData;
|
|
sizes.add(box.size);
|
|
positions.add(boxParentData.position);
|
|
}
|
|
|
|
tester.pumpWidget(
|
|
new Center(
|
|
child: new Container(
|
|
height: 100.0,
|
|
width: 100.0,
|
|
child: new Stack(<Widget>[
|
|
new PositionedTransition(
|
|
rect: rect,
|
|
performance: performance,
|
|
child: new Container(
|
|
key: key
|
|
)
|
|
)
|
|
])
|
|
)
|
|
)
|
|
); // t=0
|
|
recordMetrics();
|
|
performance.play();
|
|
tester.pump(); // t=0 again
|
|
recordMetrics();
|
|
tester.pump(const Duration(seconds: 1)); // t=1
|
|
recordMetrics();
|
|
tester.pump(const Duration(seconds: 1)); // t=2
|
|
recordMetrics();
|
|
tester.pump(const Duration(seconds: 3)); // t=5
|
|
recordMetrics();
|
|
tester.pump(const Duration(seconds: 5)); // t=10
|
|
recordMetrics();
|
|
|
|
expect(sizes, equals([const Size(10.0, 10.0), const Size(10.0, 10.0), const Size(10.0, 10.0), const Size(10.0, 10.0), const Size(10.0, 10.0), const Size(10.0, 10.0)]));
|
|
expect(positions, equals([const Point(10.0, 10.0), const Point(10.0, 10.0), const Point(17.0, 17.0), const Point(24.0, 24.0), const Point(45.0, 45.0), const Point(80.0, 80.0)]));
|
|
|
|
});
|
|
});
|
|
|
|
}
|