getTextStyle function

TextStyle? getTextStyle({
  1. required ThemeData theme,
  2. required Map<String, dynamic> props,
})

Implementation

TextStyle? getTextStyle({
  required ThemeData theme,
  required Map<String, dynamic> props,
}) {
  final textTheme = props['textStyle'] as String?;

  TextStyle? textStyle;
  switch (textTheme) {
    case 'displayLarge':
      textStyle = theme.textTheme.displayLarge;
    case 'displayMedium':
      textStyle = theme.textTheme.displayMedium;
    case 'displaySmall':
      textStyle = theme.textTheme.displaySmall;
    case 'headlineLarge':
      textStyle = theme.textTheme.headlineLarge;
    case 'headlineMedium':
      textStyle = theme.textTheme.headlineMedium;
    case 'headlineSmall':
      textStyle = theme.textTheme.headlineSmall;
    case 'titleLarge':
      textStyle = theme.textTheme.titleLarge;
    case 'titleMedium':
      textStyle = theme.textTheme.titleMedium;
    case 'titleSmall':
      textStyle = theme.textTheme.titleSmall;
    case 'bodyLarge':
      textStyle = theme.textTheme.bodyLarge;
    case 'bodyMedium':
      textStyle = theme.textTheme.bodyMedium;
    case 'bodySmall':
      textStyle = theme.textTheme.bodySmall;
    case 'labelLarge':
      textStyle = theme.textTheme.labelLarge;
    case 'labelMedium':
      textStyle = theme.textTheme.labelMedium;
    case 'labelSmall':
      textStyle = theme.textTheme.labelSmall;
    // Legacy styles for backwards compatibility
    case 'headline1':
      textStyle = theme.textTheme.displayLarge;
    case 'headline2':
      textStyle = theme.textTheme.displayMedium;
    case 'bodyText1':
      textStyle = theme.textTheme.bodyLarge;
    case 'bodyText2':
      textStyle = theme.textTheme.bodyMedium;
    default:
      textStyle = theme.textTheme.bodyMedium;
  }

  final fontWeight = props['fontWeight'] as String?;
  if (fontWeight != null) {
    textStyle = textStyle?.copyWith(fontWeight: getFontWeight(fontWeight));
  }

  final color = props['color'] as String?;
  if (color != null) {
    textStyle = textStyle?.copyWith(
      color: getColor(theme: theme, props: props),
    );
  }
  return textStyle;
}