lerp method
- double t
Returns the value this variable has at the given animation clock value.
The default implementation of this method uses the +
, -
, and *
operators on T
. The begin and end properties must therefore be
non-null by the time this method is called.
In general, however, it is possible for this to return null, especially
when t
=0.0 and begin is null, or t
=1.0 and end is null.
Implementation
@protected
T lerp(double t) {
assert(begin != null);
assert(end != null);
assert(() {
// Assertions that attempt to catch common cases of tweening types
// that do not conform to the Tween requirements.
dynamic result;
try {
// ignore: avoid_dynamic_calls
result = (begin as dynamic) + ((end as dynamic) - (begin as dynamic)) * t;
result as T;
return true;
} on NoSuchMethodError {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('Cannot lerp between "$begin" and "$end".'),
ErrorDescription(
'The type ${begin.runtimeType} might not fully implement `+`, `-`, and/or `*`. '
'See "Types with special considerations" at https://api.flutter-io.cn/flutter/animation/Tween-class.html '
'for more information.',
),
if (begin is Color || end is Color)
ErrorHint('To lerp colors, consider ColorTween instead.')
else if (begin is Rect || end is Rect)
ErrorHint('To lerp rects, consider RectTween instead.')
else
ErrorHint(
'There may be a dedicated "${begin.runtimeType}Tween" for this type, '
'or you may need to create one.',
),
]);
} on TypeError {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('Cannot lerp between "$begin" and "$end".'),
ErrorDescription(
'The type ${begin.runtimeType} returned a ${result.runtimeType} after '
'multiplication with a double value. '
'See "Types with special considerations" at https://api.flutter-io.cn/flutter/animation/Tween-class.html '
'for more information.',
),
if (begin is int || end is int)
ErrorHint('To lerp int values, consider IntTween or StepTween instead.')
else
ErrorHint(
'There may be a dedicated "${begin.runtimeType}Tween" for this type, '
'or you may need to create one.',
),
]);
}
}());
// ignore: avoid_dynamic_calls
return (begin as dynamic) + ((end as dynamic) - (begin as dynamic)) * t as T;
}