I am Trying to work with flutter ThemeExtension and I don't have quit understood how lerp
works.
Here a example ThemeExtension:
enum MyButtonVariant {
solid,
soft,
outlined,
text,
}
class MyButtonStyle extends ThemeExtension<MyButtonStyle> {
const MyButtonStyle({
this.variant,
this.margin,
});
final ButtonVariant? variant;
final EdgeInsets? margin;
@override
ThemeExtension<MyButtonStyle> copyWith({
MyButtonVariant? variant,
EdgeInsets? margin,
}) =>
MyButtonStyle(
variant: variant ?? this.variant,
margin: margin ?? this.margin,
);
@override
ThemeExtension<MyButtonStyle> lerp(
ThemeExtension<MyButtonStyle>? other, double t) {
if (other is! MyButtonStyle) {
return this;
}
return MyButtonStyle(
variant: WHAT SHOULD BE HERE? ,
margin: EdgeInsets.lerp(margin, other.margin, t),
);
}
}
What should be used in the lerp
function for variant
?
I was thinking that something like this could work:
variant: t < 0.5 ? variant : other.variant,
Is there a better solution?