Skip to content

Commit 0399af6

Browse files
committed
stream_colors [nfc]: Make StreamColorSwatches.lerp static
Discussion: #746 (comment)
1 parent 60a1774 commit 0399af6

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

lib/widgets/stream_colors.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ abstract class StreamColorSwatches {
2323

2424
StreamColorSwatch _computeForBaseColor(int base);
2525

26-
/// Gives a [StreamColorSwatches], lerped to [other] at [t].
26+
/// Gives a [StreamColorSwatches], lerped between [a] and [b] at [t].
2727
///
28-
/// If [this] and [other] are [identical], returns [this].
28+
/// If [a] and [b] are [identical], returns [this].
2929
///
3030
/// Else returns an instance whose [forBaseColor] will call
31-
/// [this.forBaseColor] and [other.forBaseColor]
31+
/// [a.forBaseColor] and [b.forBaseColor]
3232
/// and return [StreamColorSwatch.lerp]'s result on those.
3333
/// This computation is cached on the instance
3434
/// in order to save work building [t]'s animation frame when there are
3535
/// multiple UI elements using the same [subscription.color].
36-
StreamColorSwatches lerp(StreamColorSwatches other, double t) {
36+
static StreamColorSwatches lerp(StreamColorSwatches a, StreamColorSwatches b, double t) {
3737
// This short-circuit helps when [a] and [b]
3838
// are both [StreamColorSwatches.light]
3939
// or both [StreamColorSwatches.dark].
4040
// Empirically, [lerp] is called even when the theme hasn't changed,
4141
// so this is an important optimization.
42-
if (identical(this, other)) return this;
42+
if (identical(a, b)) return a;
4343

44-
return _StreamColorSwatchesLerped(this, other, t);
44+
return _StreamColorSwatchesLerped(a, b, t);
4545
}
4646
}
4747

lib/widgets/theme.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class DesignVariables extends ThemeExtension<DesignVariables> {
141141
borderBar: Color.lerp(borderBar, other.borderBar, t)!,
142142
icon: Color.lerp(icon, other.icon, t)!,
143143
title: Color.lerp(title, other.title, t)!,
144-
streamColorSwatches: streamColorSwatches.lerp(other.streamColorSwatches, t),
144+
streamColorSwatches: StreamColorSwatches.lerp(streamColorSwatches, other.streamColorSwatches, t),
145145
);
146146
}
147147
}

test/widgets/stream_colors_test.dart

+6-7
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,16 @@ void main() {
4040

4141
group('lerp', () {
4242
test('on identical instances', () {
43-
check(
44-
StreamColorSwatches.light.lerp(StreamColorSwatches.light, 0.5)
45-
).identicalTo(StreamColorSwatches.light);
43+
final light = StreamColorSwatches.light;
44+
check(StreamColorSwatches.lerp(light, light, 0.5)).identicalTo(light);
4645

47-
check(
48-
StreamColorSwatches.dark.lerp(StreamColorSwatches.dark, 0.5)
49-
).identicalTo(StreamColorSwatches.dark);
46+
final dark = StreamColorSwatches.dark;
47+
check(StreamColorSwatches.lerp(dark, dark, 0.5)).identicalTo(dark);
5048
});
5149

5250
test('from light to dark', () {
53-
final instance = StreamColorSwatches.light.lerp(StreamColorSwatches.dark, 0.4);
51+
final instance = StreamColorSwatches
52+
.lerp(StreamColorSwatches.light, StreamColorSwatches.dark, 0.4);
5453

5554
const base1 = 0xff76ce90;
5655
final swatch1 = instance.forBaseColor(base1);

0 commit comments

Comments
 (0)