Skip to content

Commit 3612a58

Browse files
committed
Add dedicated effect_entry class for better organization
1 parent eaf8ab8 commit 3612a58

File tree

2 files changed

+65
-48
lines changed

2 files changed

+65
-48
lines changed

lib/effect_entry.dart

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import 'package:flutter/widgets.dart';
2+
import 'package:flutter_animate/flutter_animate.dart';
3+
4+
import 'effects/effects.dart';
5+
import 'animate.dart';
6+
import 'animate_list.dart';
7+
8+
export 'animate.dart';
9+
export 'animate_list.dart';
10+
export 'adapters/adapters.dart';
11+
export 'effects/effects.dart';
12+
13+
export 'extensions/extensions.dart';
14+
15+
/// Because [Effect] classes are immutable and may be reused between multiple
16+
/// [Animate] (or [AnimateList]) instances, an `EffectEntry` is created to store
17+
/// values that may be different between instances. For example, due to
18+
/// `AnimateList interval`, or from inheriting values from prior effects in the chain.
19+
@immutable
20+
class EffectEntry {
21+
const EffectEntry({
22+
required this.effect,
23+
required this.delay,
24+
required this.duration,
25+
required this.curve,
26+
required this.owner,
27+
});
28+
29+
/// The delay for this entry.
30+
final Duration delay;
31+
32+
/// The duration for this entry.
33+
final Duration duration;
34+
35+
/// The curve used by this entry.
36+
final Curve curve;
37+
38+
/// The effect associated with this entry.
39+
final Effect effect;
40+
41+
/// The [Animate] instance that created this entry. This can be used by effects
42+
/// to read information about the animation. Effects _should not_ modify
43+
/// the animation (ex. by calling [Animate.addEffect]).
44+
final Animate owner;
45+
46+
/// The begin time for this entry.
47+
Duration get begin => delay;
48+
49+
/// The end time for this entry.
50+
Duration get end => delay + duration;
51+
52+
/// Builds a sub-animation that runs from 0-1, based on the properties of this entry.
53+
Animation<double> buildAnimation(
54+
AnimationController controller, {
55+
Curve? curve,
56+
}) {
57+
return buildSubAnimation(controller, begin, end, curve ?? this.curve);
58+
}
59+
60+
/// Builds an sub-animation that runs from the begin and end values of a given [Tween]
61+
Animation<T> buildTweenedAnimation<T>(AnimationController controller, Tween<T> tween) =>
62+
buildAnimation(controller).drive(tween);
63+
}

lib/flutter_animate.dart

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,15 @@ export 'animate.dart';
88
export 'animate_list.dart';
99
export 'adapters/adapters.dart';
1010
export 'effects/effects.dart';
11-
11+
export 'effect_entry.dart';
1212
export 'extensions/extensions.dart';
1313

14-
/// Because [BeginEndEffect] classes are immutable and may be reused between multiple
15-
/// [Animate] (or [AnimateList]) instances, an `EffectEntry` is created to store
16-
/// values that may be different between instances. For example, due to
17-
/// `AnimateList interval`, or from inheriting values from prior effects in the chain.
18-
@immutable
19-
class EffectEntry {
20-
const EffectEntry({
21-
required this.effect,
22-
required this.delay,
23-
required this.duration,
24-
required this.curve,
25-
required this.owner,
26-
});
27-
28-
/// The delay for this entry.
29-
final Duration delay;
30-
31-
/// The duration for this entry.
32-
final Duration duration;
33-
34-
/// The curve used by this entry.
35-
final Curve curve;
36-
37-
/// The effect associated with this entry.
38-
final Effect effect;
39-
40-
/// The [Animate] instance that created this entry. This can be used by effects
41-
/// to read information about the animation. Effects _should not_ modify
42-
/// the animation (ex. by calling [Animate.addEffect]).
43-
final Animate owner;
44-
45-
/// The begin time for this entry.
46-
Duration get begin => delay;
47-
48-
/// The end time for this entry.
49-
Duration get end => delay + duration;
50-
51-
/// Builds a sub-animation based on the properties of this entry.
52-
Animation<double> buildAnimation(
53-
AnimationController controller, {
54-
Curve? curve,
55-
}) {
56-
return buildSubAnimation(controller, begin, end, curve ?? this.curve);
57-
}
58-
}
59-
6014
/// Builds a sub-animation to the provided controller that runs from start to
6115
/// end, with the provided curve. For example, it could create an animation that
6216
/// runs from 300ms to 800ms with an easeOut curve, within a controller that has a
6317
/// total duration of 1000ms.
6418
///
65-
/// Mostly used by [EffectEntry] and [BeginEndEffect] classes.
19+
/// Mostly used by [EffectEntry] and [Effect] classes.
6620
Animation<double> buildSubAnimation(
6721
AnimationController controller,
6822
Duration begin,

0 commit comments

Comments
 (0)