decodeTextStyle static method

HWTextStyle? decodeTextStyle(
  1. DartObject? obj
)

Implementation

static HWTextStyle? decodeTextStyle(DartObject? obj) {
  if (obj == null || obj.isNull) return null;

  final typeName = obj.type?.element?.name;
  final fontSize = getField(obj, 'fontSize')?.toDoubleValue();
  final fontWeight =
      decodeEnum(getField(obj, 'fontWeight'), HWFontWeight.values);
  final color = decodeColor(getField(obj, 'color'));
  final italic = getField(obj, 'italic')?.toBoolValue();
  final underline = getField(obj, 'underline')?.toBoolValue();
  final lineThrough = getField(obj, 'lineThrough')?.toBoolValue();
  final baseStyle = decodeTextStyle(getField(obj, 'baseStyle'));

  if (typeName == 'HWRoleTextStyle') {
    final role = decodeEnum(getField(obj, 'role'), HWTextStyleRole.values)!;
    return HWRoleTextStyle(
      role: role,
      fontSize: fontSize,
      fontWeight: fontWeight,
      color: color,
      italic: italic,
      underline: underline,
      lineThrough: lineThrough,
      baseStyle: baseStyle,
    );
  }

  return HWTextStyle(
    fontSize: fontSize,
    fontWeight: fontWeight,
    color: color,
    italic: italic,
    underline: underline,
    lineThrough: lineThrough,
    baseStyle: baseStyle,
  );
}