maybeParse static method

FontWeightValue? maybeParse(
  1. dynamic value
)

Returns a FontWeightValue if the value is a valid font weight. Otherwise returns null.

Implementation

static FontWeightValue? maybeParse(dynamic value) {
  final intValue = int.tryParse(value.toString());
  if (intValue != null) {
    return FontWeightValue(intValue);
  } else if (value is String) {
    final fontWeight = _fontWeightMap.entries.firstWhereOrNull(
      (entry) => entry.value.contains(value.toLowerCase()),
    );
    if (fontWeight != null) {
      return FontWeightValue(fontWeight.key);
    }
  }
  return null;
}