@@ -26,6 +26,47 @@ class SequenceAnimationBuilder {
26
26
return Duration (microseconds: _currentLengthInMicroSeconds ());
27
27
}
28
28
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
+
29
70
/// Convenient wrapper to add an animatable after the last one is finished
30
71
///
31
72
/// [delay] is the delay to when this animation should start after the last one finishes.
0 commit comments