Skip to content

Commit 579a2a8

Browse files
committed
🔧 Update Pack 2 #10
1 parent c60cb47 commit 579a2a8

File tree

4 files changed

+32
-24
lines changed

4 files changed

+32
-24
lines changed

lib/hyper_effects.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ export 'src/effect_query.dart';
1010
export 'src/pointer_transition.dart';
1111
export 'src/apple_curves.dart';
1212
export 'src/post_frame_widget.dart';
13-
export 'src/animation_persister.dart';
13+
export 'src/animation_retainer.dart';
1414
export 'src/animated_group_effect.dart';

lib/src/animated_effect.dart

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extension AnimatedEffectExt on Widget? {
6363
int repeat = 0,
6464
bool reverse = false,
6565
bool startImmediately = false,
66+
bool skipFirstTime = false,
6667
bool resetValues = false,
6768
bool waitForLastAnimation = false,
6869
Duration delay = Duration.zero,
@@ -78,6 +79,7 @@ extension AnimatedEffectExt on Widget? {
7879
repeat: repeat,
7980
reverse: reverse,
8081
startImmediately: startImmediately,
82+
skipFirstTime: skipFirstTime,
8183
resetValues: resetValues,
8284
waitForLastAnimation: waitForLastAnimation,
8385
delay: delay,
@@ -261,6 +263,8 @@ class AnimatedEffect extends StatefulWidget {
261263
/// built, ignoring the value of [trigger] initially.
262264
final bool startImmediately;
263265

266+
final bool skipFirstTime;
267+
264268
/// Normally, an effect represents the current state of the widget and this
265269
/// animate effect is only in charge of lerping between states of those
266270
/// effect values.
@@ -301,6 +305,7 @@ class AnimatedEffect extends StatefulWidget {
301305
this.repeat = 0,
302306
this.reverse = false,
303307
this.startImmediately = false,
308+
this.skipFirstTime = false,
304309
this.resetValues = false,
305310
this.waitForLastAnimation = false,
306311
this.delay = Duration.zero,
@@ -334,7 +339,7 @@ class AnimatedEffectState extends State<AnimatedEffect>
334339
/// The animation controller that drives the animation.
335340
late final AnimationController controller = AnimationController(
336341
vsync: this,
337-
value: shouldSkip ? 1 : 0,
342+
value: widget.skipFirstTime || shouldSkip ? 1 : 0,
338343
duration: widget.duration,
339344
);
340345

@@ -426,7 +431,7 @@ class AnimatedEffectState extends State<AnimatedEffect>
426431
// ancestor's [AnimationTriggerType] is
427432
// [AnimationTriggerType.afterLast].
428433
final AnimatedEffectState? parentState =
429-
context.findAncestorStateOfType<AnimatedEffectState>();
434+
context.findAncestorStateOfType<AnimatedEffectState>();
430435
final AnimationTriggerType? triggerType =
431436
parentState?.widget.triggerType;
432437
if (parentState != null &&
@@ -438,7 +443,7 @@ class AnimatedEffectState extends State<AnimatedEffect>
438443
// [ResetAllAnimationsEffect], reset all animations in the chain.
439444
else {
440445
final resetState =
441-
context.findAncestorStateOfType<ResetAllAnimationsEffectState>();
446+
context.findAncestorStateOfType<ResetAllAnimationsEffectState>();
442447
resetState?.reset();
443448
}
444449
}
@@ -495,15 +500,16 @@ class AnimatedEffectState extends State<AnimatedEffect>
495500
Widget build(BuildContext context) {
496501
return AnimatedBuilder(
497502
animation: controller,
498-
builder: (context, child) => EffectQuery(
499-
linearValue: controller.value,
500-
curvedValue: widget.curve.transform(controller.value),
501-
isTransition: false,
502-
resetValues: widget.resetValues,
503-
duration: widget.duration,
504-
curve: widget.curve,
505-
child: child!,
506-
),
503+
builder: (context, child) =>
504+
EffectQuery(
505+
linearValue: controller.value,
506+
curvedValue: widget.curve.transform(controller.value),
507+
isTransition: false,
508+
resetValues: widget.resetValues,
509+
duration: widget.duration,
510+
curve: widget.curve,
511+
child: child!,
512+
),
507513
child: widget.child,
508514
);
509515
}

lib/src/animated_group_effect.dart

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,7 @@ class AnimatedGroup extends StatefulWidget {
109109
/// first time, but subsequent insertions should animate.
110110
final bool triggerAddImmediately;
111111

112-
/// Whether to use the swap animation when possible. If set to `false`, the
113-
/// swap animation will be skipped and the new child will have the
114-
/// [addBuilder] applied to it and the old child will have the
115-
/// [removeBuilder] applied to it.
116-
final bool useSwapWhenPossible;
112+
final bool noSwapping;
117113

118114
/// Creates an [AnimatedGroup] with the given parameters.
119115
const AnimatedGroup({
@@ -124,7 +120,7 @@ class AnimatedGroup extends StatefulWidget {
124120
this.addBuilder = _defaultAddedChildBuilder,
125121
this.swapBuilder = _defaultSwappedChildBuilder,
126122
this.triggerAddImmediately = false,
127-
this.useSwapWhenPossible = true,
123+
this.noSwapping = false,
128124
});
129125

130126
@override
@@ -162,6 +158,7 @@ class _AnimatedGroupState extends State<AnimatedGroup> {
162158
removeBuilder: widget.removeBuilder,
163159
addBuilder: widget.addBuilder,
164160
swapBuilder: widget.swapBuilder,
161+
noSwapping: widget.noSwapping,
165162
child:
166163
widget.children.length > index ? widget.children[index] : null,
167164
);
@@ -190,6 +187,8 @@ class AnimatedChild extends StatefulWidget {
190187
/// child.
191188
final bool useSnapshots;
192189

190+
final bool noSwapping;
191+
193192
/// The builder that wraps the given [child] in a widget that animates the
194193
/// removal of the child out of the widget tree.
195194
final RemovedChildBuilder removeBuilder;
@@ -208,6 +207,7 @@ class AnimatedChild extends StatefulWidget {
208207
required this.child,
209208
this.triggerAdd = true,
210209
this.useSnapshots = true,
210+
this.noSwapping = false,
211211
this.removeBuilder = _defaultRemovedChildBuilder,
212212
this.addBuilder = _defaultAddedChildBuilder,
213213
this.swapBuilder = _defaultSwappedChildBuilder,
@@ -255,7 +255,7 @@ class _AnimatedChildState extends State<AnimatedChild> {
255255
alignment: Alignment.center,
256256
clipBehavior: Clip.none,
257257
children: [
258-
if (widget.child == null)
258+
if (widget.noSwapping || widget.child == null)
259259
if (prevChild case Widget prev)
260260
KeyedSubtree(
261261
key: removedKey,
@@ -264,10 +264,12 @@ class _AnimatedChildState extends State<AnimatedChild> {
264264
if (widget.child case Widget child)
265265
widget.addBuilder(
266266
context,
267-
widget.swapBuilder(
268-
context,
269-
child,
270-
),
267+
widget.noSwapping
268+
? child
269+
: widget.swapBuilder(
270+
context,
271+
child,
272+
),
271273
() => !widget.triggerAdd,
272274
),
273275
],

0 commit comments

Comments
 (0)