Skip to content

Commit f9a4281

Browse files
BirjuVachhaniSaadArdati
authored andcommitted
🔧 Update Pack 2 #24
- Add AnimationBehavior option for AnimatedEffect. - Add `HyperEffectsAnimationConfig` inherited widget.
1 parent ee35dcf commit f9a4281

File tree

4 files changed

+64
-8
lines changed

4 files changed

+64
-8
lines changed

lib/hyper_effects.dart

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
library;
22

33
export 'src/animated_effect.dart';
4+
export 'src/animated_group_effect.dart';
5+
export 'src/animation_config.dart';
6+
export 'src/animation_retainer.dart';
7+
export 'src/apple_curves.dart';
8+
export 'src/effect_query.dart';
49
export 'src/effect_widget.dart';
510
export 'src/effects/effects.dart';
611
export 'src/extensions.dart';
7-
export 'src/scroll_phase.dart';
8-
export 'src/scroll_transition.dart';
9-
export 'src/effect_query.dart';
1012
export 'src/pointer_transition.dart';
11-
export 'src/apple_curves.dart';
1213
export 'src/post_frame_widget.dart';
13-
export 'src/animation_retainer.dart';
14-
export 'src/animated_group_effect.dart';
14+
export 'src/scroll_phase.dart';
15+
export 'src/scroll_transition.dart';

lib/src/animated_effect.dart

+14
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ extension AnimatedEffectExt on Widget? {
7676
VoidCallback? onEnd,
7777
BooleanCallback? playIf,
7878
BooleanCallback? skipIf,
79+
AnimationBehavior? animationBehavior,
7980
}) {
8081
return AnimatedEffect(
8182
triggerType: AnimationTriggerType.trigger,
@@ -91,6 +92,7 @@ extension AnimatedEffectExt on Widget? {
9192
onEnd: onEnd,
9293
playIf: playIf,
9394
skipIf: skipIf,
95+
animationBehavior: animationBehavior,
9496
child: this,
9597
);
9698
}
@@ -150,6 +152,7 @@ extension AnimatedEffectExt on Widget? {
150152
VoidCallback? onEnd,
151153
BooleanCallback? playIf,
152154
BooleanCallback? skipIf,
155+
AnimationBehavior? animationBehavior,
153156
}) {
154157
return AnimatedEffect(
155158
triggerType: AnimationTriggerType.afterLast,
@@ -164,6 +167,7 @@ extension AnimatedEffectExt on Widget? {
164167
onEnd: onEnd,
165168
playIf: playIf,
166169
skipIf: skipIf,
170+
animationBehavior: animationBehavior,
167171
child: this,
168172
);
169173
}
@@ -219,6 +223,7 @@ extension AnimatedEffectExt on Widget? {
219223
VoidCallback? onEnd,
220224
BooleanCallback? playIf,
221225
BooleanCallback? skipIf,
226+
AnimationBehavior? animationBehavior,
222227
}) {
223228
return AnimatedEffect(
224229
key: key,
@@ -233,6 +238,7 @@ extension AnimatedEffectExt on Widget? {
233238
delay: delay,
234239
playIf: playIf,
235240
skipIf: skipIf,
241+
animationBehavior: animationBehavior,
236242
child: this,
237243
);
238244
}
@@ -321,6 +327,10 @@ class AnimatedEffect extends StatefulWidget {
321327
/// the ending values.
322328
final BooleanCallback? skipIf;
323329

330+
/// The behavior of the controller when
331+
/// [AccessibilityFeatures.disableAnimations] is true.
332+
final AnimationBehavior? animationBehavior;
333+
324334
/// Creates [AnimatedEffect] widget.
325335
const AnimatedEffect({
326336
super.key,
@@ -338,6 +348,7 @@ class AnimatedEffect extends StatefulWidget {
338348
this.delay = Duration.zero,
339349
this.playIf,
340350
this.skipIf,
351+
this.animationBehavior,
341352
});
342353

343354
@override
@@ -371,6 +382,9 @@ class AnimatedEffectState extends State<AnimatedEffect>
371382
? 1
372383
: 0,
373384
duration: widget.duration,
385+
animationBehavior: widget.animationBehavior ??
386+
HyperEffectsAnimationConfig.maybeOf(context)?.animationBehavior ??
387+
AnimationBehavior.normal,
374388
);
375389

376390
/// The number of times the animation should be repeated.

lib/src/animation_config.dart

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import 'package:flutter/cupertino.dart';
2+
3+
/// Provides a way to configure the animation behavior globally for a subtree.
4+
class HyperEffectsAnimationConfig extends InheritedWidget {
5+
/// The animation behavior to use for the subtree.
6+
final AnimationBehavior? animationBehavior;
7+
8+
/// Returns the [HyperEffectsAnimationConfig] from the closest instance of
9+
/// this class that encloses the given context.
10+
static HyperEffectsAnimationConfig of(BuildContext context) {
11+
return maybeOf(context)!;
12+
}
13+
14+
/// Returns the [HyperEffectsAnimationConfig] from the closest instance of
15+
/// this class that encloses the given context.
16+
static HyperEffectsAnimationConfig? maybeOf(BuildContext context) {
17+
return context
18+
.dependOnInheritedWidgetOfExactType<HyperEffectsAnimationConfig>();
19+
}
20+
21+
/// Creates a new [HyperEffectsAnimationConfig] widget.
22+
const HyperEffectsAnimationConfig({
23+
super.key,
24+
required super.child,
25+
this.animationBehavior,
26+
});
27+
28+
@override
29+
bool updateShouldNotify(covariant HyperEffectsAnimationConfig oldWidget) {
30+
return animationBehavior != oldWidget.animationBehavior;
31+
}
32+
}

lib/src/pointer_transition.dart

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'package:flutter/widgets.dart';
22

3-
import 'apple_curves.dart';
4-
import 'effect_query.dart';
3+
import '../hyper_effects.dart';
54

65
/// Represents the pointer event for [PointerTransition].
76
class PointerTransitionEvent {
@@ -57,6 +56,7 @@ extension PointerTransitionExt on Widget {
5756
Curve curve = appleEaseInOut,
5857
Duration duration = const Duration(milliseconds: 125),
5958
Key? key,
59+
AnimationBehavior? animationBehavior,
6060
}) {
6161
return PointerTransition(
6262
key: key,
@@ -69,6 +69,7 @@ extension PointerTransitionExt on Widget {
6969
curve: curve,
7070
duration: duration,
7171
child: this,
72+
animationBehavior: animationBehavior,
7273
);
7374
}
7475
}
@@ -124,6 +125,10 @@ class PointerTransition extends StatefulWidget {
124125
/// about to reset.
125126
final Duration duration;
126127

128+
/// The behavior of the controller when
129+
/// [AccessibilityFeatures.disableAnimations] is true.
130+
final AnimationBehavior? animationBehavior;
131+
127132
/// Creates a new [PointerTransition] with the given [builder], [origin],
128133
/// [useGlobalPointer], [child], [curve], and [duration].
129134
const PointerTransition({
@@ -137,6 +142,7 @@ class PointerTransition extends StatefulWidget {
137142
this.builder,
138143
this.curve = appleEaseInOut,
139144
this.duration = const Duration(milliseconds: 125),
145+
this.animationBehavior,
140146
});
141147

142148
@override
@@ -148,6 +154,9 @@ class _PointerTransitionState extends State<PointerTransition>
148154
late final AnimationController _controller = AnimationController(
149155
vsync: this,
150156
duration: widget.duration,
157+
animationBehavior: widget.animationBehavior ??
158+
HyperEffectsAnimationConfig.maybeOf(context)?.animationBehavior ??
159+
AnimationBehavior.normal,
151160
);
152161

153162
late CurvedAnimation _animation = CurvedAnimation(

0 commit comments

Comments
 (0)