Skip to content

Commit 648c84a

Browse files
committed
Add API for last one with tag
1 parent e425496 commit 648c84a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

lib/flutter_sequence_animation.dart

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,47 @@ class SequenceAnimationBuilder {
2626
return Duration(microseconds: _currentLengthInMicroSeconds());
2727
}
2828

29+
30+
/// Convenient wrapper to add an animatable after the last one with a specific tag finished is finished
31+
///
32+
/// The tags must be comparable! Strings, enums work, when using objects, be sure to override the == method
33+
///
34+
/// [delay] is the delay to when this animation should start after the last one finishes.
35+
/// For example:
36+
///
37+
///```dart
38+
/// SequenceAnimation sequenceAnimation = new SequenceAnimationBuilder()
39+
/// .addAnimatable(
40+
/// animatable: new ColorTween(begin: Colors.red, end: Colors.yellow),
41+
/// from: const Duration(seconds: 0),
42+
/// to: const Duration(seconds: 2),
43+
/// tag: "color",
44+
/// ).addAnimatableAfterLastOneWithTag(
45+
/// animatable: new ColorTween(begin: Colors.red, end: Colors.yellow),
46+
/// delay: const Duration(seconds: 1),
47+
/// duration: const Duration(seconds: 1),
48+
/// tag: "animation",
49+
/// lastTag: "color",
50+
/// ).animate(controller);
51+
///
52+
/// ```
53+
///
54+
/// The animation with tag "animation" will start at second 3 and run until second 4.
55+
///
56+
SequenceAnimationBuilder addAnimatableAfterLastOneWithTag({
57+
@required Object lastTag,
58+
@required Animatable animatable,
59+
Duration delay: Duration.zero,
60+
@required Duration duration,
61+
Curve curve: Curves.linear,
62+
@required Object tag,
63+
}) {
64+
assert(_animations.isNotEmpty, "Can not add animatable after last one if there is no animatable yet");
65+
var start = _animations.lastWhere((it) => it.tag == lastTag, orElse: () => null)?.to;
66+
assert(start != null, "Animation with tag $lastTag can not be found before $tag");
67+
return addAnimatable(animatable: animatable, from: start + delay, to: start + delay + duration, tag: tag, curve: curve);
68+
}
69+
2970
/// Convenient wrapper to add an animatable after the last one is finished
3071
///
3172
/// [delay] is the delay to when this animation should start after the last one finishes.

0 commit comments

Comments
 (0)