update method
- @override
Sets the action 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 action. Every
action 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 (startVal is Offset) {
// Point
double xStart = (startVal as Offset).dx;
double yStart = (startVal as Offset).dy;
double xDelta = _delta.dx;
double yDelta = _delta.dy;
newVal = new Offset(xStart + xDelta * t, yStart + yDelta * t);
} else if (startVal is Size) {
// Size
double wStart = (startVal as Size).width;
double hStart = (startVal as Size).height;
double wDelta = _delta.width;
double hDelta = _delta.height;
newVal = new Size(wStart + wDelta * t, hStart + hDelta * t);
} else if (startVal is Rect) {
// Rect
double lStart = (startVal as Rect).left;
double tStart = (startVal as Rect).top;
double rStart = (startVal as Rect).right;
double bStart = (startVal as Rect).bottom;
double lDelta = _delta.left;
double tDelta = _delta.top;
double rDelta = _delta.right;
double bDelta = _delta.bottom;
newVal = new Rect.fromLTRB(lStart + lDelta * t, tStart + tDelta * t, rStart + rDelta * t, bStart + bDelta * t);
} else if (startVal is double) {
// Doubles
newVal = (startVal as double) + _delta * t;
} else if (startVal is Color) {
// Colors
int aNew = ((startVal as Color).alpha + (_delta.alpha * t).toInt()).clamp(0, 255);
int rNew = ((startVal as Color).red + (_delta.red * t).toInt()).clamp(0, 255);
int gNew = ((startVal as Color).green + (_delta.green * t).toInt()).clamp(0, 255);
int bNew = ((startVal as Color).blue + (_delta.blue * t).toInt()).clamp(0, 255);
newVal = new Color.fromARGB(aNew, rNew, gNew, bNew);
} else {
// Oopses
assert(false);
}
setter(newVal);
}