PickerFont.fromFontSpec constructor

PickerFont.fromFontSpec(
  1. String fontSpec
)

Constructs a PickerFont from a font spec description (a shorthand string that can describe a font), e.g. "Roboto:700i".

Implementation

factory PickerFont.fromFontSpec(String fontSpec) {
  final fontSpecSplit = fontSpec.split(":");
  if (fontSpecSplit.length == 1) {
    return PickerFont(fontFamily: fontSpecSplit[0]);
  } else {
    return PickerFont(
        fontFamily: fontSpecSplit[0],
        fontWeight: fontWeightValues[fontSpecSplit[1].replaceAll("i", "")] ??
            FontWeight.w400,
        fontStyle: fontSpecSplit[1].contains("i")
            ? FontStyle.italic
            : FontStyle.normal);
  }
}