Skip to content

Commit ae5999e

Browse files
committed
🔧 Update Pack 2 #7
1 parent 14adaac commit ae5999e

File tree

11 files changed

+497
-96
lines changed

11 files changed

+497
-96
lines changed

example/lib/stories/group_animation.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class _GroupAnimationState extends State<GroupAnimation> {
2121
];
2222
final List<String> tags2 = [
2323
'family',
24+
'work',
2425
'friends',
2526
'sports',
26-
'work',
2727
];
2828

2929
@override
@@ -39,10 +39,10 @@ class _GroupAnimationState extends State<GroupAnimation> {
3939
color: Theme.of(context).colorScheme.surface,
4040
borderRadius: BorderRadius.circular(20),
4141
),
42-
// clipBehavior: Clip.antiAlias,
43-
child: AnimatedGroup(
42+
clipBehavior: Clip.antiAlias,
43+
child: AnimatedGroup(
44+
triggerAddImmediately: false,
4445
builder: (context, children) => Row(children: children),
45-
valueGetter: (child, i) => tags[i],
4646
children: [
4747
for (int i = 0; i < tags.length; i++)
4848
Padding(

example/pubspec.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ environment:
1010
dependencies:
1111
flutter:
1212
sdk: flutter
13-
adaptive_theme: ^3.4.1
13+
adaptive_theme: ^3.6.0
1414
flutter_box_transform: ^0.4.2
1515
hyper_effects:
1616
path: ../
17-
google_fonts: ^6.1.0
17+
google_fonts: ^6.2.1
1818
smooth_page_indicator: ^1.1.0
1919

2020
dev_dependencies:
2121
flutter_test:
2222
sdk: flutter
23-
flutter_lints: ^3.0.1
23+
web: ^0.5.1
24+
flutter_lints: ^3.0.2
2425

2526
flutter:
2627
uses-material-design: true

lib/src/animated_effect.dart

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ extension AnimatedEffectExt on Widget? {
4545
///
4646
/// The [delay] parameter is used to set a delay before the animation starts.
4747
///
48+
/// The [startImmediately] parameter is used to determine whether the
49+
/// animation should be triggered immediately when the widget is built,
50+
/// ignoring the value of [trigger] initially.
51+
///
4852
/// The [playIf] parameter is used to determine whether the animation should
4953
/// be played or skipped. If the callback returns false, the animation will
5054
/// be skipped, even when it is explicitly triggered.
5155
///
52-
/// The [startImmediately] parameter is used to determine whether the
53-
/// animation should be triggered immediately when the widget is built,
54-
/// ignoring the value of [trigger] initially.
56+
/// The [skipIf] parameter is used to determine whether the animation should
57+
/// be skipped by setting the animation value to 1, effectively skipping the
58+
/// animation to the ending values.
5559
Widget animate({
5660
required Object? trigger,
5761
Duration duration = const Duration(milliseconds: 350),
@@ -64,6 +68,7 @@ extension AnimatedEffectExt on Widget? {
6468
Duration delay = Duration.zero,
6569
VoidCallback? onEnd,
6670
BooleanCallback? playIf,
71+
BooleanCallback? skipIf,
6772
}) {
6873
return AnimatedEffect(
6974
triggerType: AnimationTriggerType.trigger,
@@ -78,6 +83,7 @@ extension AnimatedEffectExt on Widget? {
7883
delay: delay,
7984
onEnd: onEnd,
8085
playIf: playIf,
86+
skipIf: skipIf,
8187
child: this,
8288
);
8389
}
@@ -112,27 +118,25 @@ extension AnimatedEffectExt on Widget? {
112118
/// When false, the animation will animate from the previous effect state
113119
/// towards the current state.
114120
///
115-
/// The [waitForLastAnimation] parameter is used to determine whether the
116-
/// animation should be reset on subsequent triggers. If this animation is
117-
/// re-triggered, it will reset the current active animation and re-drive
118-
/// from the beginning. Setting this to true will force the animation to
119-
/// wait for the last animation in the chain to finish before starting.
120-
///
121121
/// The [delay] parameter is used to set a delay before the animation starts.
122122
///
123123
/// The [playIf] parameter is used to determine whether the animation should
124124
/// be played or skipped. If the callback returns false, the animation will
125125
/// be skipped, even when it is explicitly triggered.
126+
///
127+
/// The [skipIf] parameter is used to determine whether the animation should
128+
/// be skipped by setting the animation value to 1, effectively skipping the
129+
/// animation to the ending values.
126130
Widget animateAfter({
127131
Duration duration = const Duration(milliseconds: 350),
128132
Curve curve = appleEaseInOut,
129133
int repeat = 0,
130134
bool reverse = false,
131135
bool resetValues = false,
132-
bool waitForLastAnimation = false,
133136
Duration delay = Duration.zero,
134137
VoidCallback? onEnd,
135138
BooleanCallback? playIf,
139+
BooleanCallback? skipIf,
136140
}) {
137141
return AnimatedEffect(
138142
triggerType: AnimationTriggerType.afterLast,
@@ -142,10 +146,11 @@ extension AnimatedEffectExt on Widget? {
142146
repeat: repeat,
143147
reverse: reverse,
144148
resetValues: resetValues,
145-
waitForLastAnimation: waitForLastAnimation,
149+
waitForLastAnimation: false,
146150
delay: delay,
147151
onEnd: onEnd,
148152
playIf: playIf,
153+
skipIf: skipIf,
149154
child: this,
150155
);
151156
}
@@ -187,6 +192,9 @@ extension AnimatedEffectExt on Widget? {
187192
/// be played or skipped. If the callback returns false, the animation will
188193
/// be skipped, even when it is explicitly triggered.
189194
///
195+
/// The [skipIf] parameter is used to determine whether the animation should
196+
/// be skipped by setting the animation value to 1, effectively skipping the
197+
/// animation to the ending values.
190198
AnimatedEffect oneShot({
191199
Key? key,
192200
Duration duration = const Duration(milliseconds: 350),
@@ -198,6 +206,7 @@ extension AnimatedEffectExt on Widget? {
198206
Duration delay = Duration.zero,
199207
VoidCallback? onEnd,
200208
BooleanCallback? playIf,
209+
BooleanCallback? skipIf,
201210
}) {
202211
return AnimatedEffect(
203212
key: key,
@@ -211,6 +220,7 @@ extension AnimatedEffectExt on Widget? {
211220
waitForLastAnimation: waitForLastAnimation,
212221
delay: delay,
213222
playIf: playIf,
223+
skipIf: skipIf,
214224
child: this,
215225
);
216226
}
@@ -274,6 +284,11 @@ class AnimatedEffect extends StatefulWidget {
274284
/// be skipped, even when it is explicitly triggered.
275285
final BooleanCallback? playIf;
276286

287+
/// A callback that determines whether the animation should be skipped by
288+
/// setting the animation value to 1, effectively skipping the animation to
289+
/// the ending values.
290+
final BooleanCallback? skipIf;
291+
277292
/// Creates [AnimatedEffect] widget.
278293
const AnimatedEffect({
279294
super.key,
@@ -290,6 +305,7 @@ class AnimatedEffect extends StatefulWidget {
290305
this.waitForLastAnimation = false,
291306
this.delay = Duration.zero,
292307
this.playIf,
308+
this.skipIf,
293309
});
294310

295311
@override
@@ -311,10 +327,14 @@ class AnimatedEffectState extends State<AnimatedEffect>
311327
/// on the [playIf] callback.
312328
bool get shouldPlay => widget.playIf?.call() ?? true;
313329

330+
/// Returns whether the animation should be skipped based on the [skipIf]
331+
/// callback.
332+
bool get shouldSkip => widget.skipIf?.call() ?? false;
333+
314334
/// The animation controller that drives the animation.
315335
late final AnimationController controller = AnimationController(
316336
vsync: this,
317-
value: 0,
337+
value: shouldSkip ? 1 : 0,
318338
duration: widget.duration,
319339
);
320340

@@ -405,14 +425,14 @@ class AnimatedEffectState extends State<AnimatedEffect>
405425
// tree for the next [AnimatedEffect] and trigger it manually if the
406426
// ancestor's [AnimationTriggerType] is
407427
// [AnimationTriggerType.afterLast].
408-
final parentState =
428+
final AnimatedEffectState? parentState =
409429
context.findAncestorStateOfType<AnimatedEffectState>();
410-
if (parentState != null) {
411-
final triggerType = parentState.widget.triggerType;
412-
if (triggerType == AnimationTriggerType.afterLast) {
413-
// Trigger the next animation.
414-
await parentState.drive();
415-
}
430+
final AnimationTriggerType? triggerType =
431+
parentState?.widget.triggerType;
432+
if (parentState != null &&
433+
triggerType == AnimationTriggerType.afterLast) {
434+
// Trigger the next animation.
435+
await parentState.drive();
416436
}
417437
// If instead of an [AnimatedEffect] we find a
418438
// [ResetAllAnimationsEffect], reset all animations in the chain.
@@ -441,6 +461,10 @@ class AnimatedEffectState extends State<AnimatedEffect>
441461
return driveFuture = ensureDelay(() async {
442462
if (!mounted) return;
443463
if (!shouldPlay) return;
464+
if (shouldSkip) {
465+
controller.value = 1;
466+
return;
467+
}
444468
if (widget.reverse && shouldReverse) {
445469
shouldReverse = false;
446470
await controller.reverse().catchError((err) {

0 commit comments

Comments
 (0)