Skip to content

Commit 45ef6b2

Browse files
committed
Refactor to simplify inheritence chain.
Renamed `buildAnimation` to `buildBeginEndAnimation` to make things a little more clear.
1 parent 3612a58 commit 45ef6b2

13 files changed

+15
-23
lines changed

lib/effect_entry.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import 'package:flutter/widgets.dart';
22
import 'package:flutter_animate/flutter_animate.dart';
33

4-
import 'effects/effects.dart';
5-
import 'animate.dart';
6-
import 'animate_list.dart';
7-
84
export 'animate.dart';
95
export 'animate_list.dart';
106
export 'adapters/adapters.dart';

lib/effects/blur_effect.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class BlurEffect extends BeginEndEffect<Offset> {
3535
AnimationController controller,
3636
EffectEntry entry,
3737
) {
38-
Animation<Offset> animation = buildAnimation(controller, entry);
38+
Animation<Offset> animation = buildBeginEndAnimation(controller, entry);
3939
return getOptimizedBuilder<Offset>(
4040
animation: animation,
4141
builder: (_, __) {

lib/effects/custom_effect.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CustomEffect extends BeginEndEffect<double> {
3838
AnimationController controller,
3939
EffectEntry entry,
4040
) {
41-
Animation<double> animation = buildAnimation(controller, entry);
41+
Animation<double> animation = buildTweenedAnimation(controller, entry);
4242
return getOptimizedBuilder<double>(
4343
animation: animation,
4444
builder: (ctx, __) => builder(ctx, animation.value, child),

lib/effects/effect.dart

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,9 @@ class BeginEndEffect<T> extends Effect {
2525
/// default value when appropriate.
2626
final T? end;
2727

28-
/// Returns an animation based on the controller, entry, and begin/end values.
29-
Animation<T> buildAnimation(
30-
AnimationController controller,
31-
EffectEntry entry,
32-
) {
33-
return entry.buildAnimation(controller).drive(Tween<T>(begin: begin, end: end));
34-
}
28+
/// Helper method for concrete effects to easily create an Animation<T> from the current begin/end values.
29+
Animation<T> buildBeginEndAnimation(AnimationController controller, EffectEntry entry) =>
30+
entry.buildTweenedAnimation(controller, Tween(begin: begin, end: end));
3531
}
3632

3733
/// Class that defines the required interface and helper methods for
@@ -41,7 +37,7 @@ class BeginEndEffect<T> extends Effect {
4137
///
4238
/// It can be instantiated and added to Animate, but has no visual effect.
4339
@immutable
44-
class Effect<T> {
40+
class Effect {
4541
const Effect({this.delay, this.duration, this.curve});
4642

4743
/// The specified delay for the effect. If null, will use the delay from the

lib/effects/fade_effect.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class FadeEffect extends BeginEndEffect<double> {
3131
EffectEntry entry,
3232
) {
3333
return FadeTransition(
34-
opacity: buildAnimation(controller, entry),
34+
opacity: buildBeginEndAnimation(controller, entry),
3535
child: child,
3636
);
3737
}

lib/effects/move_effect.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class MoveEffect extends BeginEndEffect<Offset> {
4141
AnimationController controller,
4242
EffectEntry entry,
4343
) {
44-
Animation<Offset> animation = buildAnimation(controller, entry);
44+
Animation<Offset> animation = buildTweenedAnimation(controller, entry);
4545
return getOptimizedBuilder<Offset>(
4646
animation: animation,
4747
builder: (_, __) {

lib/effects/rotate_effect.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class RotateEffect extends BeginEndEffect<double> {
3838
AnimationController controller,
3939
EffectEntry entry,
4040
) {
41-
Animation<double> animation = buildAnimation(controller, entry);
41+
Animation<double> animation = buildTweenedAnimation(controller, entry);
4242
return RotationTransition(
4343
turns: animation,
4444
alignment: alignment ?? Alignment.center,

lib/effects/saturate_effect.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class SaturateEffect extends BeginEndEffect<double> {
3838
AnimationController controller,
3939
EffectEntry entry,
4040
) {
41-
Animation<double> animation = buildAnimation(controller, entry);
41+
Animation<double> animation = buildTweenedAnimation(controller, entry);
4242
return getOptimizedBuilder<double>(
4343
animation: animation,
4444
builder: (_, __) {

lib/effects/scale_effect.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ScaleEffect extends BeginEndEffect<Offset> {
3636
AnimationController controller,
3737
EffectEntry entry,
3838
) {
39-
Animation<Offset> animation = buildAnimation(controller, entry);
39+
Animation<Offset> animation = buildTweenedAnimation(controller, entry);
4040
return getOptimizedBuilder<Offset>(
4141
animation: animation,
4242
builder: (_, __) {

lib/effects/shake_effect.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ShakeEffect extends BeginEndEffect<double> {
6060
final bool shouldTranslate = offset != Offset.zero;
6161
if (!shouldRotate && !shouldTranslate) return child;
6262

63-
final Animation<double> animation = buildAnimation(controller, entry);
63+
final Animation<double> animation = buildTweenedAnimation(controller, entry);
6464
final int count = (entry.duration.inMilliseconds / 1000 * hz).round();
6565

6666
return getOptimizedBuilder<double>(

lib/effects/shimmer_effect.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ShimmerEffect extends BeginEndEffect<double> {
6060
AnimationController controller,
6161
EffectEntry entry,
6262
) {
63-
Animation<double> animation = buildAnimation(controller, entry);
63+
Animation<double> animation = buildTweenedAnimation(controller, entry);
6464
return getOptimizedBuilder<double>(
6565
animation: animation,
6666
builder: (_, __) {

lib/effects/slide_effect.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class SlideEffect extends BeginEndEffect<Offset> {
3737
EffectEntry entry,
3838
) {
3939
return SlideTransition(
40-
position: buildAnimation(controller, entry),
40+
position: buildTweenedAnimation(controller, entry),
4141
child: child,
4242
);
4343
}

lib/effects/tint_effect.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class TintEffect extends BeginEndEffect<double> {
4444
AnimationController controller,
4545
EffectEntry entry,
4646
) {
47-
Animation<double> animation = buildAnimation(controller, entry);
47+
Animation<double> animation = buildBeginEndAnimation(controller, entry);
4848
return getOptimizedBuilder<double>(
4949
animation: animation,
5050
builder: (_, __) {

0 commit comments

Comments
 (0)