lerp method
Linear interpolation between two tokens
Implementation
FlyFontWeightToken lerp(FlyFontWeightToken other, double t) {
final result = <String, FontWeight>{};
final allKeys = {..._allValues.keys, ...other._allValues.keys};
for (final key in allKeys) {
final valueA = _allValues[key];
final valueB = other._allValues[key];
if (valueA != null && valueB != null) {
final weightA = valueA.index;
final weightB = valueB.index;
final interpolatedIndex = (weightA + (weightB - weightA) * t).round();
result[key] = FontWeight
.values[interpolatedIndex.clamp(0, FontWeight.values.length - 1)];
} else if (valueA != null) {
result[key] = valueA;
} else if (valueB != null) {
result[key] = valueB;
}
}
return FlyFontWeightToken(
thin: result['thin']!,
extralight: result['extralight']!,
light: result['light']!,
normal: result['normal']!,
medium: result['medium']!,
semibold: result['semibold']!,
bold: result['bold']!,
extrabold: result['extrabold']!,
black: result['black']!,
extras: Map.fromEntries(
result.entries.where(
(e) => ![
'thin',
'extralight',
'light',
'normal',
'medium',
'semibold',
'bold',
'extrabold',
'black',
].contains(e.key),
),
),
);
}