Skip to content

Commit

Permalink
Implement FlipEffect test
Browse files Browse the repository at this point in the history
  • Loading branch information
gskinner committed Feb 13, 2023
1 parent 8373c79 commit 40f3b9a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
43 changes: 25 additions & 18 deletions lib/src/effects/flip_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,33 @@ class FlipEffect extends Effect<double> {
Animation<double> animation = buildAnimation(controller, entry);
return getOptimizedBuilder<double>(
animation: animation,
builder: (_, __) {
double value = animation.value * pi;

final Matrix4 mtx = Matrix4(
1.0, 0.0, 0.0, 0.0, //
0.0, 1.0, 0.0, 0.0, //
0.0, 0.0, 1.0, 0.002 * perspective, //
0.0, 0.0, 0.0, 1.0,
);
if (value != 0) {
if (direction == Axis.vertical) {
mtx.rotateX(value);
} else {
mtx.rotateY(value);
}
}
builder: (_, __) => Transform(
alignment: alignment,
transform: getTransformMatrix(animation.value, direction, perspective),
child: child,
),
);
}

return Transform(alignment: alignment, transform: mtx, child: child);
},
static Matrix4 getTransformMatrix(
double value,
Axis direction,
double perspective,
) {
final Matrix4 mtx = Matrix4(
1.0, 0.0, 0.0, 0.0, //
0.0, 1.0, 0.0, 0.0, //
0.0, 0.0, 1.0, 0.002 * perspective, //
0.0, 0.0, 0.0, 1.0,
);
if (value != 0) {
if (direction == Axis.vertical) {
mtx.rotateX(value * pi);
} else {
mtx.rotateY(value * pi);
}
}
return mtx;
}
}

Expand Down
25 changes: 24 additions & 1 deletion test/effects/flip_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_animate/flutter_animate.dart';

import '../tester_extensions.dart';

void main() {
// TODO: expose FlipEffect.getTransformMatrix (name TBD) and use in test
testWidgets('FlipEffect: core', (tester) async {
Axis direction = Axis.vertical;
double perspective = 2;
final animation = const FlutterLogo().animate().flip(
duration: 1000.ms,
direction: direction,
perspective: perspective,
begin: 0,
end: 1,
);

// Check halfway,
await tester.pumpAnimation(animation, initialDelay: 500.ms);
// Create a matrix and compare to the one in the widget tree
var mtx = FlipEffect.getTransformMatrix(0.5, direction, perspective);
tester.expectWidgetWithBool<Transform>(
(o) => o.transform == mtx, true, 'transform @ 500ms');
});
}

0 comments on commit 40f3b9a

Please sign in to comment.