diff --git a/lib/ui/lerp.dart b/lib/ui/lerp.dart index 0bb0a08b7242d..33e52f694eb97 100644 --- a/lib/ui/lerp.dart +++ b/lib/ui/lerp.dart @@ -40,3 +40,16 @@ int _clampInt(int value, int min, int max) { return value; } } + +/// Linearly interpolate between two `Duration`s. +Duration? lerpDuration(Duration? a, Duration? b, double t) { + if (a == null && b == null) + return null; + + a ??= Duration.zero; + b ??= Duration.zero; + + return Duration( + microseconds: _lerpInt(a.inMicroseconds, b.inMicroseconds, t).round(), + ); +} \ No newline at end of file