toStrings for Animations and Animatables
This commit is contained in:
@@ -28,6 +28,9 @@ class _AlwaysCompleteAnimation extends Animation<double> {
|
||||
|
||||
@override
|
||||
double get value => 1.0;
|
||||
|
||||
@override
|
||||
String toString() => 'kAlwaysCompleteAnimation';
|
||||
}
|
||||
|
||||
/// An animation that is always complete.
|
||||
@@ -57,6 +60,9 @@ class _AlwaysDismissedAnimation extends Animation<double> {
|
||||
|
||||
@override
|
||||
double get value => 0.0;
|
||||
|
||||
@override
|
||||
String toString() => 'kAlwaysDismissedAnimation';
|
||||
}
|
||||
|
||||
/// An animation that is always dismissed.
|
||||
@@ -96,6 +102,11 @@ class AlwaysStoppedAnimation<T> extends Animation<T> {
|
||||
|
||||
@override
|
||||
AnimationStatus get status => AnimationStatus.forward;
|
||||
|
||||
@override
|
||||
String toStringDetails() {
|
||||
return '${super.toStringDetails()} $value; paused';
|
||||
}
|
||||
}
|
||||
|
||||
/// Implements most of the [Animation] interface, by deferring its behavior to a
|
||||
@@ -195,6 +206,13 @@ class ProxyAnimation extends Animation<double>
|
||||
|
||||
@override
|
||||
double get value => _parent != null ? _parent.value : _value;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
if (parent == null)
|
||||
return '$runtimeType(null; ${super.toStringDetails()} ${value.toStringAsFixed(3)})';
|
||||
return '$parent\u27A9$runtimeType';
|
||||
}
|
||||
}
|
||||
|
||||
/// An animation that is the reverse of another animation.
|
||||
@@ -251,6 +269,11 @@ class ReverseAnimation extends Animation<double>
|
||||
case AnimationStatus.dismissed: return AnimationStatus.completed;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '$parent\u27AA$runtimeType';
|
||||
}
|
||||
}
|
||||
|
||||
/// An animation that applies a curve to another animation.
|
||||
@@ -317,10 +340,13 @@ class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<do
|
||||
}
|
||||
}
|
||||
|
||||
bool get _useForwardCurve {
|
||||
return reverseCurve == null || (_curveDirection ?? parent.status) != AnimationStatus.reverse;
|
||||
}
|
||||
|
||||
@override
|
||||
double get value {
|
||||
final bool useForwardCurve = reverseCurve == null || (_curveDirection ?? parent.status) != AnimationStatus.reverse;
|
||||
Curve activeCurve = useForwardCurve ? curve : reverseCurve;
|
||||
Curve activeCurve = _useForwardCurve ? curve : reverseCurve;
|
||||
|
||||
double t = parent.value;
|
||||
if (activeCurve == null)
|
||||
@@ -331,6 +357,15 @@ class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<do
|
||||
}
|
||||
return activeCurve.transform(t);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
if (reverseCurve == null)
|
||||
return '$parent\u27A9$curve';
|
||||
if (_useForwardCurve)
|
||||
return '$parent\u27A9$curve\u2092\u2099/$reverseCurve';
|
||||
return '$parent\u27A9$curve/$reverseCurve\u2092\u2099';
|
||||
}
|
||||
}
|
||||
|
||||
enum _TrainHoppingMode { minimize, maximize }
|
||||
@@ -439,4 +474,11 @@ class TrainHoppingAnimation extends Animation<double>
|
||||
_nextTrain = null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
if (_nextTrain != null)
|
||||
return '$currentTrain\u27A9$runtimeType(next: $_nextTrain)';
|
||||
return '$currentTrain\u27A9$runtimeType(no next)';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,11 @@ abstract class Curve {
|
||||
/// Returns a new curve that is the reversed inversion of this one.
|
||||
/// This is often useful as the reverseCurve of an [Animation].
|
||||
Curve get flipped => new FlippedCurve(this);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '$runtimeType';
|
||||
}
|
||||
}
|
||||
|
||||
/// The identity map over the unit interval.
|
||||
@@ -49,6 +54,11 @@ class SawTooth extends Curve {
|
||||
t *= count;
|
||||
return t - t.truncateToDouble();
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '$runtimeType($count)';
|
||||
}
|
||||
}
|
||||
|
||||
/// A curve that is 0.0 until start, then curved from 0.0 to 1.0 at end, then 1.0.
|
||||
@@ -76,6 +86,13 @@ class Interval extends Curve {
|
||||
return t;
|
||||
return curve.transform(t);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
if (curve is! Linear)
|
||||
return '$runtimeType($start\u22EF$end)\u27A9$curve';
|
||||
return '$runtimeType($start\u22EF$end)';
|
||||
}
|
||||
}
|
||||
|
||||
/// A cubic polynomial mapping of the unit interval.
|
||||
@@ -102,6 +119,11 @@ class Cubic extends Curve {
|
||||
end = midpoint;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '$runtimeType(${a.toStringAsFixed(2)}, ${b.toStringAsFixed(2)}, ${c.toStringAsFixed(2)}, ${d.toStringAsFixed(2)})';
|
||||
}
|
||||
}
|
||||
|
||||
double _bounce(double t) {
|
||||
@@ -126,6 +148,11 @@ class FlippedCurve extends Curve {
|
||||
|
||||
@override
|
||||
double transform(double t) => 1.0 - curve.transform(1.0 - t);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '$runtimeType($curve)';
|
||||
}
|
||||
}
|
||||
|
||||
/// An oscillating curve that grows in magnitude.
|
||||
@@ -173,6 +200,11 @@ class ElasticInCurve extends Curve {
|
||||
t = t - 1.0;
|
||||
return -math.pow(2.0, 10.0 * t) * math.sin((t - s) * (math.PI * 2.0) / period);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '$runtimeType($period)';
|
||||
}
|
||||
}
|
||||
|
||||
/// An oscillating curve that shrinks in magnitude while overshooting its bounds.
|
||||
@@ -186,6 +218,11 @@ class ElasticOutCurve extends Curve {
|
||||
double s = period / 4.0;
|
||||
return math.pow(2.0, -10 * t) * math.sin((t - s) * (math.PI * 2.0) / period) + 1.0;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '$runtimeType($period)';
|
||||
}
|
||||
}
|
||||
|
||||
/// An oscillating curve that grows and then shrinks in magnitude while overshooting its bounds.
|
||||
@@ -203,6 +240,11 @@ class ElasticInOutCurve extends Curve {
|
||||
else
|
||||
return math.pow(2.0, -10.0 * t) * math.sin((t - s) * (math.PI * 2.0) / period) * 0.5 + 1.0;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '$runtimeType($period)';
|
||||
}
|
||||
}
|
||||
|
||||
/// A collection of common animation curves.
|
||||
|
||||
@@ -33,7 +33,6 @@ abstract class Animatable<T> {
|
||||
class _AnimatedEvaluation<T> extends Animation<T> with AnimationWithParentMixin<double> {
|
||||
_AnimatedEvaluation(this.parent, this._evaluatable);
|
||||
|
||||
/// The animation from which this value is derived.
|
||||
@override
|
||||
final Animation<double> parent;
|
||||
|
||||
@@ -41,6 +40,16 @@ class _AnimatedEvaluation<T> extends Animation<T> with AnimationWithParentMixin<
|
||||
|
||||
@override
|
||||
T get value => _evaluatable.evaluate(parent);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '$parent\u27A9$_evaluatable';
|
||||
}
|
||||
|
||||
@override
|
||||
String toStringDetails() {
|
||||
return '${super.toStringDetails()} $_evaluatable';
|
||||
}
|
||||
}
|
||||
|
||||
class _ChainedEvaluation<T> extends Animatable<T> {
|
||||
@@ -54,6 +63,11 @@ class _ChainedEvaluation<T> extends Animatable<T> {
|
||||
double value = _parent.evaluate(animation);
|
||||
return _evaluatable.evaluate(new AlwaysStoppedAnimation<double>(value));
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '$_parent\u27A9$_evaluatable';
|
||||
}
|
||||
}
|
||||
|
||||
/// A linear interpolation between a beginning and ending value.
|
||||
|
||||
Reference in New Issue
Block a user