Skip to content

Commit

Permalink
Fiz blink issue for AnimatedList
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sneha-s committed Apr 9, 2024
1 parent 819dc19 commit 62b5ac6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
5 changes: 2 additions & 3 deletions lib/src/animation/provider/animation_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,16 @@ class EffectEntry {
Duration get begin => delay;

/// The end time for this entry.
Duration get end => duration;
Duration get end => begin+duration;

/// Builds a sub-animation based on the properties of this entry.
CurveTween buildAnimation({
required Duration totalDuration,
Curve? curve,
}) {
int ttlT = duration.inMicroseconds;
int beginT = begin.inMicroseconds, endT = end.inMicroseconds;
return CurveTween(
curve: Interval(beginT / ttlT, endT / totalDuration.inMicroseconds,
curve: Interval(beginT / totalDuration.inMicroseconds, endT / totalDuration.inMicroseconds,
curve: curve ?? this.curve),
);
}
Expand Down
11 changes: 8 additions & 3 deletions lib/src/builder/motion_animated_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class MotionBuilderState extends State<MotionBuilder>
for (int i = 0; i < widget.initialCount; i++) {
childrenMap[i] = MotionData();
}

super.initState();
}

Expand Down Expand Up @@ -485,10 +486,10 @@ class MotionBuilderState extends State<MotionBuilder>
if (entry.key == itemIndex) {
updatedChildrenMap[itemIndex] = motionData;
updatedChildrenMap[entry.key + 1] =
entry.value.copyWith(startOffset: _itemOffsetAt(entry.key));
entry.value.copyWith(startOffset: _itemOffsetAt(entry.key), endOffset: _itemOffsetAt(entry.key+1), visible: false);
} else if (entry.key > itemIndex) {
updatedChildrenMap[entry.key + 1] =
entry.value.copyWith(startOffset: _itemOffsetAt(entry.key));
entry.value.copyWith(startOffset: _itemOffsetAt(entry.key), endOffset: _itemOffsetAt(entry.key+1), visible: false);
} else {
updatedChildrenMap[entry.key] = entry.value;
}
Expand Down Expand Up @@ -586,7 +587,7 @@ class MotionBuilderState extends State<MotionBuilder>
continue;
} else {
updatedChildrenMap[entry.key - 1] = childrenMap[entry.key]!
.copyWith(startOffset: _itemOffsetAt(entry.key));
.copyWith(startOffset: _itemOffsetAt(entry.key), endOffset: _itemOffsetAt(entry.key-1), visible: false);
}
}
}
Expand All @@ -600,11 +601,14 @@ class MotionBuilderState extends State<MotionBuilder>
final itemRenderBox =
_items[index]?.context.findRenderObject() as RenderBox?;
if (itemRenderBox == null) return Offset.zero;


return itemRenderBox.localToGlobal(Offset.zero);
}

@override
Widget build(BuildContext context) {

super.build(context);
return widget.delegateBuilder != null
? SliverGrid(
Expand Down Expand Up @@ -648,6 +652,7 @@ class MotionBuilderState extends State<MotionBuilder>
index: index,
key: itemGlobalKey,
motionData: motionData,
isGrid: isGrid,
updateMotionData: (MotionData motionData) {
final itemOffset = _itemOffsetAt(index);
childrenMap[index] = motionData.copyWith(
Expand Down
19 changes: 9 additions & 10 deletions lib/src/builder/motion_list_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,22 @@ abstract class MotionListBaseState<
void addEffect(AnimationEffect effect, List<EffectEntry> enteries,
{required bool enter}) {
Duration zero = Duration.zero;

if (effect.duration != null) {
if (enter) {
_enterDuration = effect.duration! > _enterDuration
? effect.duration!
final timeForAnimation= (effect.delay??zero) + (effect.duration??kAnimationDuration);
if (enter) {
_enterDuration = timeForAnimation > _enterDuration
? timeForAnimation
: _enterDuration;
assert(_enterDuration >= zero, "Duration can not be negative");
} else {
_exitDuration =
effect.duration! > _exitDuration ? effect.duration! : _exitDuration;
timeForAnimation > _exitDuration ? timeForAnimation : _exitDuration;
assert(_exitDuration >= zero, "Duration can not be negative");
}
}

EffectEntry entry = EffectEntry(
animationEffect: effect,
delay: effect.delay ?? zero,
duration: effect.duration ?? removeDuration,
duration: effect.duration ?? kAnimationDuration,
curve: effect.curve ?? Curves.linear);

enteries.add(entry);
Expand Down Expand Up @@ -203,7 +202,7 @@ abstract class MotionListBaseState<
Widget animatedChild = child;
for (EffectEntry entry in _enterAnimations) {
animatedChild = entry.animationEffect
.build(context, animatedChild, animation, entry, enterDuration);
.build(context, animatedChild, animation, entry, insertDuration);
}
return animatedChild;
}
Expand All @@ -219,7 +218,7 @@ abstract class MotionListBaseState<
Widget animatedChild = child;
for (EffectEntry entry in _exitAnimations) {
animatedChild = entry.animationEffect
.build(context, animatedChild, animation, entry, exitDuration);
.build(context, animatedChild, animation, entry, removeDuration);
}
return animatedChild;
}
Expand Down
8 changes: 7 additions & 1 deletion lib/src/component/motion_animated_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ class MotionAnimatedContent extends StatefulWidget {
final Widget child;
final Function(MotionData)? updateMotionData;
final CapturedThemes? capturedThemes;
final bool isGrid;

const MotionAnimatedContent(
{Key? key,
required this.index,
required this.motionData,
required this.child,
this.updateMotionData,
required this.capturedThemes})
required this.capturedThemes,
required this.isGrid,
})
: super(key: key);

@override
Expand Down Expand Up @@ -86,6 +89,9 @@ class MotionAnimatedContentState extends State<MotionAnimatedContent>
visible = true;
});
}
if(oldWidget.index!= widget.index && !_dragging && widget.isGrid){
_updateAnimationTranslation();
}
widget.updateMotionData?.call(widget.motionData);
});
super.didUpdateWidget(oldWidget);
Expand Down

0 comments on commit 62b5ac6

Please sign in to comment.