fromMap static method

AttributedString? fromMap(
  1. Map<String, dynamic>? map, {
  2. EnumMethod? enumMethod,
})

Gets a possible AttributedString instance from a Map value.

Implementation

static AttributedString? fromMap(
  Map<String, dynamic>? map, {
  EnumMethod? enumMethod,
}) {
  if (map == null) {
    return null;
  }
  final instance = AttributedString(
    backgroundColor: map['backgroundColor'] != null
        ? UtilColor.fromStringRepresentation(map['backgroundColor'])
        : null,
    baselineOffset: map['baselineOffset'],
    expansion: map['expansion'],
    foregroundColor: map['foregroundColor'] != null
        ? UtilColor.fromStringRepresentation(map['foregroundColor'])
        : null,
    kern: map['kern'],
    ligature: map['ligature'],
    obliqueness: map['obliqueness'],
    strikethroughColor: map['strikethroughColor'] != null
        ? UtilColor.fromStringRepresentation(map['strikethroughColor'])
        : null,
    strikethroughStyle: switch (enumMethod ?? EnumMethod.nativeValue) {
      EnumMethod.nativeValue => UnderlineStyle.fromNativeValue(
        map['strikethroughStyle'],
      ),
      EnumMethod.value => UnderlineStyle.fromValue(map['strikethroughStyle']),
      EnumMethod.name => UnderlineStyle.byName(map['strikethroughStyle']),
    },
    string: map['string'],
    strokeColor: map['strokeColor'] != null
        ? UtilColor.fromStringRepresentation(map['strokeColor'])
        : null,
    strokeWidth: map['strokeWidth'],
    textEffect: switch (enumMethod ?? EnumMethod.nativeValue) {
      EnumMethod.nativeValue =>
        AttributedStringTextEffectStyle.fromNativeValue(map['textEffect']),
      EnumMethod.value => AttributedStringTextEffectStyle.fromValue(
        map['textEffect'],
      ),
      EnumMethod.name => AttributedStringTextEffectStyle.byName(
        map['textEffect'],
      ),
    },
    underlineColor: map['underlineColor'] != null
        ? UtilColor.fromStringRepresentation(map['underlineColor'])
        : null,
    underlineStyle: switch (enumMethod ?? EnumMethod.nativeValue) {
      EnumMethod.nativeValue => UnderlineStyle.fromNativeValue(
        map['underlineStyle'],
      ),
      EnumMethod.value => UnderlineStyle.fromValue(map['underlineStyle']),
      EnumMethod.name => UnderlineStyle.byName(map['underlineStyle']),
    },
  );
  return instance;
}