Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit a283719

Browse files
committed
fix: floatTween could be nullable in animatedOpacity
1 parent 952de6b commit a283719

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

Runtime/animation/tween.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ public NullableFloatTween(float? begin = null, float? end = null) : base(begin:
191191
}
192192

193193
public override float? lerp(float t) {
194+
D.assert(this.begin != null);
195+
D.assert(this.end != null);
194196
return this.begin + (this.end - this.begin) * t;
195197
}
196198
}

Runtime/widgets/implicit_animations.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,7 @@ public override void dispose() {
215215
}
216216

217217
public bool _shouldAnimateTween<T2>(Tween<T2> tween, T2 targetValue) {
218-
var curTargetValue = tween.end;
219-
220-
if (tween.end == null || typeof(T2) == typeof(float) &&
221-
(float) Convert.ChangeType(tween.end, typeof(float)) == -1.0f) {
222-
curTargetValue = tween.begin;
223-
}
224-
return !targetValue.Equals(curTargetValue);
218+
return !targetValue.Equals(tween.end != null ? tween.end : tween.begin);
225219
}
226220

227221
public void _updateTween<T2>(Tween<T2> tween, T2 targetValue) {
@@ -472,16 +466,18 @@ public override void debugFillProperties(DiagnosticPropertiesBuilder properties)
472466
}
473467

474468
class _AnimatedOpacityState : ImplicitlyAnimatedWidgetState<AnimatedOpacity> {
475-
FloatTween _opacity;
469+
NullableFloatTween _opacity;
476470
Animation<float> _opacityAnimation;
477471

478472
protected override void forEachTween(TweenVisitor visitor) {
479-
this._opacity = (FloatTween) visitor.visit(this, this._opacity, this.widget.opacity,
480-
(float value) => new FloatTween(begin: value, end: -1.0f));
473+
this._opacity = (NullableFloatTween) visitor.visit(this, this._opacity, this.widget.opacity,
474+
(float? value) => new NullableFloatTween(begin: value));
481475
}
482476

483477
protected override void didUpdateTweens() {
484-
this._opacityAnimation = this.animation.drive(this._opacity);
478+
float? endValue = this._opacity.end ?? this._opacity.begin ?? null;
479+
D.assert(endValue != null);
480+
this._opacityAnimation = this.animation.drive(new FloatTween(begin: this._opacity.begin.Value, end: endValue.Value));
485481
}
486482

487483
public override Widget build(BuildContext context) {

0 commit comments

Comments
 (0)