update method
Sets the motion to a specific point in time. The t
value that is passed
in is a normalized value 0.0 to 1.0 of the duration of the motion. Every
motion will always recieve a callback with the end time point (1.0),
unless it is cancelled.
Implementation
@override
void update(double t) {
dynamic newVal;
if (start is Offset) {
// Point
double xStart = (start as Offset).dx;
double yStart = (start as Offset).dy;
double xDelta = _delta.dx;
double yDelta = _delta.dy;
newVal = Offset(xStart + xDelta * t, yStart + yDelta * t);
} else if (start is Size) {
// Size
double wStart = (start as Size).width;
double hStart = (start as Size).height;
double wDelta = _delta.width;
double hDelta = _delta.height;
newVal = Size(wStart + wDelta * t, hStart + hDelta * t);
} else if (start is Rect) {
// Rect
double lStart = (start as Rect).left;
double tStart = (start as Rect).top;
double rStart = (start as Rect).right;
double bStart = (start as Rect).bottom;
double lDelta = _delta.left;
double tDelta = _delta.top;
double rDelta = _delta.right;
double bDelta = _delta.bottom;
newVal = Rect.fromLTRB(lStart + lDelta * t, tStart + tDelta * t,
rStart + rDelta * t, bStart + bDelta * t);
} else if (start is double) {
// Doubles
newVal = (start as double) + _delta * t;
} else if (start is Color) {
// Colors
int aNew = ((start as Color).alpha + (_delta.alpha * t).toInt())
.clamp(0, 255) as int;
int rNew = ((start as Color).red + (_delta.red * t).toInt()).clamp(0, 255)
as int;
int gNew = ((start as Color).green + (_delta.green * t).toInt())
.clamp(0, 255) as int;
int bNew = ((start as Color).blue + (_delta.blue * t).toInt())
.clamp(0, 255) as int;
newVal = Color.fromARGB(aNew, rNew, gNew, bNew);
} else {
// Oopses
assert(false);
}
setter(newVal);
}