textStyle method
Implementation
TextStyleSpec? textStyle(DartValue? v) {
final d = deref(v);
switch (d) {
case ObjectValue(type: 'TextStyle'):
return TextStyleSpec(
fontFamily: string(d['fontFamily']),
fontSize: number(d['fontSize']),
fontWeight: fontWeight(d['fontWeight']),
italic: switch (enumName(d['fontStyle'])) {
'italic' => true,
'normal' => false,
_ => null,
},
color: color(d['color']),
height: number(d['height']),
letterSpacing: number(d['letterSpacing']),
);
case AccessValue(:final target, :final name)
when _endsWith(target, const {'textTheme', 'primaryTextTheme'}):
return theme.textStyle(name);
case CallValue(target: RefValue(path: ['GoogleFonts']), :final method)
when !method.endsWith('TextTheme'):
// GoogleFonts.inter(textStyle: ..., fontSize: ...) or getFont('Inter').
final family = method == 'getFont'
? string(d.positional.firstOrNull)
: googleFontFamily(method);
return TextStyleSpec(fontFamily: family)
.merge(textStyle(d.named['textStyle']))
.merge(textStyle(ObjectValue(type: 'TextStyle', named: d.named)))
.merge(TextStyleSpec(fontFamily: family));
case CallValue(target: final target?, method: 'copyWith'):
final base = textStyle(target) ?? const TextStyleSpec();
return base.merge(
textStyle(ObjectValue(type: 'TextStyle', named: d.named)),
);
case CallValue(target: final target?, method: 'merge'):
final base = textStyle(target) ?? const TextStyleSpec();
return base.merge(textStyle(d.positional.firstOrNull));
case CallValue(target: final target?, method: 'apply'):
final base = textStyle(target) ?? const TextStyleSpec();
return base.merge(TextStyleSpec(color: color(d.named['color'])));
case ConditionalValue(:final then):
return textStyle(then);
default:
return null;
}
}