addFontWeight static method

TextStyle addFontWeight(
  1. TextStyle textStyle,
  2. String value
)

Creates a TextStyle to handle CSS font-weight

Implementation

static TextStyle addFontWeight(TextStyle textStyle, String value) {
  final List<String> supportedNumValues = <String>[
    '100',
    '200',
    '300',
    '400',
    '500',
    '600',
    '700',
    '800',
    '900',
  ];
  if (supportedNumValues.contains(value)) {
    return textStyle.copyWith(
        fontWeight: FontWeight.values[supportedNumValues.indexOf(value)]);
  }

  switch (value.toLowerCase()) {
    case 'normal':
      return textStyle.copyWith(fontWeight: FontWeight.normal);
    case 'medium':
      return textStyle.copyWith(fontWeight: FontWeight.w500);
    case 'bold':
      return textStyle.copyWith(fontWeight: FontWeight.bold);
    default:
      return textStyle.copyWith(fontWeight: FontWeight.bold);
  }
}