Jonny Borges

add more animation tests

import 'dart:math';
import 'dart:ui';
import 'package:flutter/widgets.dart';
import 'get_animated_builder.dart';
typedef OffsetBuilder = Offset Function(BuildContext, double);
class FadeInAnimation extends OpacityAnimation {
FadeInAnimation({
super.key,
... ... @@ -89,47 +92,83 @@ class ScaleAnimation extends GetAnimatedBuilder<double> {
);
}
class SlideAnimation extends GetAnimatedBuilder<Offset> {
SlideAnimation({
// class SlideAnimation extends GetAnimatedBuilder<Offset> {
// SlideAnimation({
// super.key,
// required super.duration,
// required super.delay,
// required super.child,
// super.onComplete,
// required Offset begin,
// required Offset end,
// super.idleValue = const Offset(0, 0),
// }) : super(
// builder: (context, value, child) => Transform.translate(
// offset: value,
// child: child,
// ),
// tween: Tween(begin: begin, end: end),
// );
// }
class BounceAnimation extends GetAnimatedBuilder<double> {
BounceAnimation({
super.key,
required super.duration,
required super.delay,
required super.child,
super.onComplete,
required Offset begin,
required Offset end,
super.idleValue = const Offset(0, 0),
super.curve = Curves.bounceOut,
required double begin,
required double end,
super.idleValue = 0,
}) : super(
builder: (context, value, child) => Transform.translate(
offset: value,
builder: (context, value, child) => Transform.scale(
scale: 1 + value.abs(),
child: child,
),
tween: Tween(begin: begin, end: end),
tween: Tween<double>(begin: begin, end: end),
);
}
class BounceAnimation extends GetAnimatedBuilder<double> {
BounceAnimation({
class SpinAnimation extends GetAnimatedBuilder<double> {
SpinAnimation({
super.key,
required super.duration,
required super.delay,
required super.child,
super.onComplete,
super.curve = Curves.bounceOut,
super.idleValue = 0,
}) : super(
builder: (context, value, child) => Transform.rotate(
angle: value * pi / 180.0,
child: child,
),
tween: Tween<double>(begin: 0, end: 360),
);
}
class SizeAnimation extends GetAnimatedBuilder<double> {
SizeAnimation({
super.key,
required super.duration,
required super.delay,
required super.child,
super.onComplete,
super.idleValue = 0,
required double begin,
required double end,
super.idleValue = 0,
}) : super(
builder: (context, value, child) => Transform.scale(
scale: 1 + value.abs(),
scale: value,
child: child,
),
tween: Tween<double>(begin: begin, end: end),
);
}
class ShakeAnimation extends GetAnimatedBuilder<double> {
ShakeAnimation({
class BlurAnimation extends GetAnimatedBuilder<double> {
BlurAnimation({
super.key,
required super.duration,
required super.delay,
... ... @@ -139,69 +178,207 @@ class ShakeAnimation extends GetAnimatedBuilder<double> {
required double end,
super.idleValue = 0,
}) : super(
builder: (context, value, child) => Transform.rotate(
angle: value * pi / 180.0,
builder: (context, value, child) => BackdropFilter(
filter: ImageFilter.blur(
sigmaX: value,
sigmaY: value,
),
child: child,
),
tween: Tween<double>(begin: begin, end: end),
);
}
class SpinAnimation extends GetAnimatedBuilder<double> {
SpinAnimation({
class FlipAnimation extends GetAnimatedBuilder<double> {
FlipAnimation({
super.key,
required super.duration,
required super.delay,
required super.child,
super.onComplete,
required double begin,
required double end,
super.idleValue = 0,
}) : super(
builder: (context, value, child) => Transform.rotate(
angle: value * pi / 180.0,
builder: (context, value, child) {
final radians = value * pi;
return Transform(
transform: Matrix4.rotationY(radians),
alignment: Alignment.center,
child: child,
);
},
tween: Tween<double>(begin: begin, end: end),
);
}
class WaveAnimation extends GetAnimatedBuilder<double> {
WaveAnimation({
super.key,
required super.duration,
required super.delay,
required super.child,
super.onComplete,
required double begin,
required double end,
super.idleValue = 0,
}) : super(
builder: (context, value, child) => Transform(
transform: Matrix4.translationValues(
0.0,
20.0 * sin(value * pi * 2),
0.0,
),
child: child,
),
tween: Tween<double>(begin: 0, end: 360),
tween: Tween<double>(begin: begin, end: end),
);
}
class ColorAnimation extends GetAnimatedBuilder<Color?> {
ColorAnimation({
class WobbleAnimation extends GetAnimatedBuilder<double> {
WobbleAnimation({
super.key,
required super.duration,
required super.delay,
required super.child,
super.onComplete,
required Color begin,
required Color end,
Color? idleColor,
required double begin,
required double end,
super.idleValue = 0,
}) : super(
builder: (context, value, child) => ColorFiltered(
colorFilter: ColorFilter.mode(
Color.lerp(begin, end, value!.value.toDouble())!,
BlendMode.srcIn,
),
builder: (context, value, child) => Transform(
transform: Matrix4.identity()
..setEntry(3, 2, 0.001)
..rotateZ(sin(value * pi * 2) * 0.1),
alignment: Alignment.center,
child: child,
),
idleValue: idleColor ?? begin,
tween: ColorTween(begin: begin, end: end),
tween: Tween<double>(begin: begin, end: end),
);
}
class SizeAnimation extends GetAnimatedBuilder<double> {
SizeAnimation({
class SlideInLeftAnimation extends SlideAnimation {
SlideInLeftAnimation({
super.key,
required super.duration,
required super.delay,
required super.child,
super.onComplete,
required super.begin,
required super.end,
super.idleValue = 0,
}) : super(
offsetBuild: (context, value) =>
Offset(value * MediaQuery.of(context).size.width, 0),
);
}
class SlideInRightAnimation extends SlideAnimation {
SlideInRightAnimation({
super.key,
required super.duration,
required super.delay,
required super.child,
super.onComplete,
required super.begin,
required super.end,
super.idleValue = 0,
}) : super(
offsetBuild: (context, value) =>
Offset((1 - value) * MediaQuery.of(context).size.width, 0),
);
}
class SlideInUpAnimation extends SlideAnimation {
SlideInUpAnimation({
super.key,
required super.duration,
required super.delay,
required super.child,
super.onComplete,
required super.begin,
required super.end,
super.idleValue = 0,
}) : super(
offsetBuild: (context, value) =>
Offset(0, value * MediaQuery.of(context).size.height),
);
}
class SlideInDownAnimation extends SlideAnimation {
SlideInDownAnimation({
super.key,
required super.duration,
required super.delay,
required super.child,
super.onComplete,
required super.begin,
required super.end,
super.idleValue = 0,
}) : super(
offsetBuild: (context, value) =>
Offset(0, (1 - value) * MediaQuery.of(context).size.height),
);
}
class SlideAnimation extends GetAnimatedBuilder<double> {
SlideAnimation({
super.key,
required super.duration,
required super.delay,
required super.child,
required double begin,
required double end,
required OffsetBuilder offsetBuild,
super.onComplete,
super.idleValue = 0,
}) : super(
builder: (context, value, child) => Transform.scale(
scale: value,
builder: (context, value, child) => Transform.translate(
offset: offsetBuild(context, value),
child: child,
),
tween: Tween<double>(begin: begin, end: end),
);
}
// class ZoomAnimation extends GetAnimatedBuilder<double> {
// ZoomAnimation({
// super.key,
// required super.duration,
// required super.delay,
// required super.child,
// super.onComplete,
// required double begin,
// required double end,
// super.idleValue = 0,
// }) : super(
// builder: (context, value, child) => Transform.scale(
// scale: lerpDouble(1, end, value)!,
// child: child,
// ),
// tween: Tween<double>(begin: begin, end: end),
// );
// }
class ColorAnimation extends GetAnimatedBuilder<Color?> {
ColorAnimation({
super.key,
required super.duration,
required super.delay,
required super.child,
super.onComplete,
required Color begin,
required Color end,
Color? idleColor,
}) : super(
builder: (context, value, child) => ColorFiltered(
colorFilter: ColorFilter.mode(
Color.lerp(begin, end, value!.value.toDouble())!,
BlendMode.srcIn,
),
child: child,
),
idleValue: idleColor ?? begin,
tween: ColorTween(begin: begin, end: end),
);
}
... ...
... ... @@ -81,8 +81,9 @@ extension AnimationExtension on Widget {
}
GetAnimatedBuilder slide({
required Offset begin,
required Offset end,
required OffsetBuilder offset,
double begin = 0,
double end = 1,
Duration duration = _defaultDuration,
Duration delay = _defaultDelay,
ValueSetter<AnimationController>? onComplete,
... ... @@ -94,6 +95,7 @@ extension AnimationExtension on Widget {
begin: begin,
end: end,
onComplete: onComplete,
offsetBuild: offset,
child: this,
);
}
... ... @@ -116,7 +118,21 @@ extension AnimationExtension on Widget {
);
}
GetAnimatedBuilder shake({
GetAnimatedBuilder spin({
Duration duration = _defaultDuration,
Duration delay = _defaultDelay,
ValueSetter<AnimationController>? onComplete,
bool isSequential = false,
}) {
return SpinAnimation(
duration: duration,
delay: _getDelay(isSequential, delay),
onComplete: onComplete,
child: this,
);
}
GetAnimatedBuilder size({
required double begin,
required double end,
Duration duration = _defaultDuration,
... ... @@ -124,7 +140,7 @@ extension AnimationExtension on Widget {
ValueSetter<AnimationController>? onComplete,
bool isSequential = false,
}) {
return ShakeAnimation(
return SizeAnimation(
duration: duration,
delay: _getDelay(isSequential, delay),
begin: begin,
... ... @@ -134,29 +150,51 @@ extension AnimationExtension on Widget {
);
}
GetAnimatedBuilder spin({
GetAnimatedBuilder blur({
double begin = 0,
double end = 15,
Duration duration = _defaultDuration,
Duration delay = _defaultDelay,
ValueSetter<AnimationController>? onComplete,
bool isSequential = false,
}) {
return SpinAnimation(
return BlurAnimation(
duration: duration,
delay: _getDelay(isSequential, delay),
begin: begin,
end: end,
onComplete: onComplete,
child: this,
);
}
GetAnimatedBuilder flip({
double begin = 0,
double end = 1,
Duration duration = _defaultDuration,
Duration delay = _defaultDelay,
ValueSetter<AnimationController>? onComplete,
bool isSequential = false,
}) {
return FlipAnimation(
duration: duration,
delay: _getDelay(isSequential, delay),
begin: begin,
end: end,
onComplete: onComplete,
child: this,
);
}
GetAnimatedBuilder size({
required double begin,
required double end,
GetAnimatedBuilder wave({
double begin = 0,
double end = 1,
Duration duration = _defaultDuration,
Duration delay = _defaultDelay,
ValueSetter<AnimationController>? onComplete,
bool isSequential = false,
}) {
return SizeAnimation(
return WaveAnimation(
duration: duration,
delay: _getDelay(isSequential, delay),
begin: begin,
... ...
... ... @@ -101,14 +101,14 @@ void main() {
testWidgets('slide() returns a SlideAnimation',
(WidgetTester tester) async {
const begin = Offset.zero;
const end = Offset.zero;
const begin = 0;
const end = 1;
final widget = buildWidget();
final animation = widget.slide(begin: begin, end: end);
final animation = widget.slide(offset: (_, __) => const Offset(0, 0));
expect(animation, isA<SlideAnimation>());
_testDefaultValues<Offset>(
_testDefaultValues(
animation: animation, widget: widget, begin: begin, end: end);
});
... ... @@ -130,39 +130,65 @@ void main() {
);
});
testWidgets('shake() returns a ShakeAnimation',
(WidgetTester tester) async {
testWidgets('spin() returns a SpinAnimation', (WidgetTester tester) async {
final widget = buildWidget();
const begin = 0.0;
const end = 360;
final animation = widget.spin();
expect(animation, isA<SpinAnimation>());
_testDefaultValues(
animation: animation, widget: widget, begin: begin, end: end);
});
testWidgets('size() returns a SizeAnimation', (WidgetTester tester) async {
final widget = buildWidget();
const begin = 0.9;
const end = 1.1;
final animation = widget.size(begin: begin, end: end);
expect(animation, isA<SizeAnimation>());
_testDefaultValues(
animation: animation, widget: widget, begin: begin, end: end);
});
testWidgets('blur() returns a BlurAnimation', (WidgetTester tester) async {
final widget = buildWidget();
final animation = widget.shake(begin: begin, end: end);
expect(animation, isA<ShakeAnimation>());
const begin = 0.9;
const end = 1.1;
final animation = widget.blur(begin: begin, end: end);
expect(animation, isA<BlurAnimation>());
_testDefaultValues(
animation: animation, widget: widget, begin: begin, end: end);
});
testWidgets('spin() returns a SpinAnimation', (WidgetTester tester) async {
testWidgets('flip() returns a FlipAnimation', (WidgetTester tester) async {
final widget = buildWidget();
const begin = 0.0;
const end = 360;
final animation = widget.spin();
expect(animation, isA<SpinAnimation>());
const begin = 0.9;
const end = 1.1;
final animation = widget.flip(begin: begin, end: end);
expect(animation, isA<FlipAnimation>());
_testDefaultValues(
animation: animation, widget: widget, begin: begin, end: end);
});
testWidgets('size() returns a SizeAnimation', (WidgetTester tester) async {
testWidgets('wave() returns a FlipAnimation', (WidgetTester tester) async {
final widget = buildWidget();
const begin = 0.9;
const end = 1.1;
final animation = widget.size(begin: begin, end: end);
final animation = widget.wave(begin: begin, end: end);
expect(animation, isA<SizeAnimation>());
expect(animation, isA<WaveAnimation>());
_testDefaultValues(
animation: animation, widget: widget, begin: begin, end: end);
... ...
... ... @@ -325,45 +325,124 @@ void main() {
await tester.pumpAndSettle();
});
testWidgets('SlideAnimation', (WidgetTester tester) async {
testWidgets('WaveAnimation', (WidgetTester tester) async {
await tester.pumpWidget(
SlideAnimation(
WaveAnimation(
duration: const Duration(seconds: 1),
delay: Duration.zero,
begin: Offset.zero,
end: const Offset(1.0, 1.0),
begin: 1.0,
end: 2.0,
child: Container(),
),
);
expect(find.byType(SlideAnimation), findsOneWidget);
expect(find.byType(WaveAnimation), findsOneWidget);
await tester.pumpAndSettle();
});
testWidgets('BounceAnimation', (WidgetTester tester) async {
testWidgets('WobbleAnimation', (WidgetTester tester) async {
await tester.pumpWidget(
BounceAnimation(
WobbleAnimation(
duration: const Duration(seconds: 1),
delay: Duration.zero,
begin: 0.0,
end: 1.0,
begin: 1.0,
end: 2.0,
child: Container(),
),
);
expect(find.byType(BounceAnimation), findsOneWidget);
expect(find.byType(WobbleAnimation), findsOneWidget);
await tester.pumpAndSettle();
});
testWidgets('SlideAnimation', (WidgetTester tester) async {
await tester.pumpWidget(
SlideAnimation(
offsetBuild: (p0, p1) => const Offset(1.0, 1.0),
duration: const Duration(seconds: 1),
delay: Duration.zero,
begin: 0,
end: 1,
child: Container(),
),
);
expect(find.byType(SlideAnimation), findsOneWidget);
await tester.pumpAndSettle();
});
testWidgets('SlideInLeftAnimation', (WidgetTester tester) async {
await tester.pumpWidget(
_Wrapper(
child: SlideInLeftAnimation(
duration: const Duration(seconds: 1),
delay: Duration.zero,
begin: 1.0,
end: 2.0,
child: Container(),
),
),
);
expect(find.byType(SlideInLeftAnimation), findsOneWidget);
await tester.pumpAndSettle();
});
testWidgets('SlideInRightAnimation', (WidgetTester tester) async {
await tester.pumpWidget(
_Wrapper(
child: SlideInRightAnimation(
duration: const Duration(seconds: 1),
delay: Duration.zero,
begin: 1.0,
end: 2.0,
child: Container(),
),
),
);
expect(find.byType(SlideInRightAnimation), findsOneWidget);
await tester.pumpAndSettle();
});
testWidgets('SlideInUpAnimation', (WidgetTester tester) async {
await tester.pumpWidget(
_Wrapper(
child: SlideInUpAnimation(
duration: const Duration(seconds: 1),
delay: Duration.zero,
begin: 1.0,
end: 2.0,
child: Container(),
),
),
);
expect(find.byType(SlideInUpAnimation), findsOneWidget);
await tester.pumpAndSettle();
});
testWidgets('SlideInDownAnimation', (WidgetTester tester) async {
await tester.pumpWidget(
_Wrapper(
child: SlideInDownAnimation(
duration: const Duration(seconds: 1),
delay: Duration.zero,
begin: 1.0,
end: 2.0,
child: Container(),
),
),
);
expect(find.byType(SlideInDownAnimation), findsOneWidget);
await tester.pumpAndSettle();
});
testWidgets('ShakeAnimation', (WidgetTester tester) async {
testWidgets('BounceAnimation', (WidgetTester tester) async {
await tester.pumpWidget(
ShakeAnimation(
BounceAnimation(
duration: const Duration(seconds: 1),
delay: Duration.zero,
begin: 0.0,
end: 10.0,
end: 1.0,
child: Container(),
),
);
expect(find.byType(ShakeAnimation), findsOneWidget);
expect(find.byType(BounceAnimation), findsOneWidget);
await tester.pumpAndSettle();
});
... ... @@ -406,4 +485,32 @@ void main() {
expect(find.byType(SizeAnimation), findsOneWidget);
await tester.pumpAndSettle();
});
testWidgets('BlurAnimation', (WidgetTester tester) async {
await tester.pumpWidget(
BlurAnimation(
duration: const Duration(seconds: 1),
delay: Duration.zero,
begin: 1.0,
end: 2.0,
child: Container(),
),
);
expect(find.byType(BlurAnimation), findsOneWidget);
await tester.pumpAndSettle();
});
testWidgets('FlipAnimation', (WidgetTester tester) async {
await tester.pumpWidget(
FlipAnimation(
duration: const Duration(seconds: 1),
delay: Duration.zero,
begin: 1.0,
end: 2.0,
child: Container(),
),
);
expect(find.byType(FlipAnimation), findsOneWidget);
await tester.pumpAndSettle();
});
}
... ...