style static method
TextStyle
style({
- required BuildContext context,
- double size = 14,
- FontWeightProtocol weight = const _DefaultFontWeight(),
- Color color = Colors.black,
- double? lineHeight,
- FontKey fontKey = FontKey.primary,
Creates a scaled, theme-aware TextStyle.
Parameters:
context: BuildContext used to resolve theme and device sizesize: Base font size in logical pixels (default: 14)weight: Font weight abstraction (default: regular / 400)color: Text color (default: Colors.black)lineHeight: Line height multiplier relative to font size. Examples:- 1.2 → tight
- 1.4 → normal (recommended for body text)
- 1.6 → relaxed / descriptive text
Notes:
- Line height is not scaled manually
- It scales naturally with font size
nullpreserves Flutter default behavior
Implementation
static TextStyle style({
required BuildContext context,
double size = 14,
FontWeightProtocol weight = const _DefaultFontWeight(),
Color color = Colors.black,
double? lineHeight,
FontKey fontKey = FontKey.primary,
}) {
// -----------------------------------------------------------------------
// Responsive scaling
// -----------------------------------------------------------------------
final scale = DeviceHelper.getScalingFactor(context);
final scaledSize = size * scale;
// -----------------------------------------------------------------------
// Convert abstract font weight → Flutter FontWeight
//
// FontWeight.values index mapping:
// w100 → 0, w200 → 1, ... w900 → 8
// -----------------------------------------------------------------------
final fontWeightIndex = (weight.weightValue ~/ 100) - 1;
final fontWeight = FontWeight
.values[fontWeightIndex.clamp(0, FontWeight.values.length - 1)];
// -----------------------------------------------------------------------
// Resolve font family from typography theme extension
// -----------------------------------------------------------------------
final fontFamily = FontRegistry.getFont(fontKey);
return TextStyle(
inherit: true, // Allows theme/default overrides and safer merging
fontFamily: fontFamily,
fontSize: scaledSize,
fontWeight: fontWeight,
color: color,
height: lineHeight == null ? null : lineHeight * scale,
);
}