textTheme method
Evaluates a TextTheme expression into the entries it sets.
TextTheme(...) yields only the named entries (as Flutter's partial
text themes do); Theme.of(context).textTheme yields the full theme.
Implementation
Map<String, TextStyleSpec>? textTheme(DartValue? v) {
final d = deref(v);
switch (d) {
case ObjectValue(type: 'TextTheme'):
return {
for (final MapEntry(:key, :value) in d.named.entries)
key: ?textStyle(value),
};
case AccessValue(name: 'textTheme'):
return {
for (final name in theme.textTheme.keys) name: theme.textStyle(name)!,
};
case CallValue(target: RefValue(path: ['GoogleFonts']), :final method)
when method.endsWith('TextTheme'):
// Flutter's google_fonts starts from ThemeData.light().textTheme.
final baseline = MaterialTheme.baseline(ThemeBrightness.light);
final base =
textTheme(d.positional.firstOrNull) ??
{
for (final name in baseline.textTheme.keys)
name: baseline.textStyle(name)!,
};
final family = googleFontFamily(
method.substring(0, method.length - 'TextTheme'.length),
);
return {
for (final MapEntry(:key, :value) in base.entries)
key: value.merge(TextStyleSpec(fontFamily: family)),
};
case CallValue(target: final target?, method: 'apply'):
final base = textTheme(target);
if (base == null) return null;
final family = string(d.named['fontFamily']);
final display = color(d.named['displayColor']);
final body = color(d.named['bodyColor']);
return {
for (final MapEntry(:key, :value) in base.entries)
key: value.merge(
TextStyleSpec(
fontFamily: family,
color: _displayColorStyles.contains(key) ? display : body,
),
),
};
case CallValue(target: final target?, method: 'copyWith'):
final base = textTheme(target);
if (base == null) return null;
return {
...base,
for (final MapEntry(:key, :value) in d.named.entries)
key: ?textStyle(value),
};
case CallValue(target: final target?, method: 'merge'):
final base = textTheme(target);
final other = textTheme(d.positional.firstOrNull);
if (base == null) return other;
if (other == null) return base;
return {
for (final key in {...base.keys, ...other.keys})
key: (base[key] ?? const TextStyleSpec()).merge(other[key]),
};
default:
return null;
}
}