parseTextDecoration static method

TextDecoration? parseTextDecoration(
  1. Object? source
)

Implementation

static TextDecoration? parseTextDecoration(Object? source) {
  if (source is! String || source.isEmpty) return null;
  final key = source.toString();
  if (key.startsWith("TextDecoration.lineThrough") || key == "lineThrough") {
    return TextDecoration.lineThrough;
  }
  if (key.startsWith("TextDecoration.overline") || key == "overline") {
    return TextDecoration.overline;
  }
  if (key.startsWith("TextDecoration.underline") || key == "underline") {
    return TextDecoration.underline;
  }
  if (key.startsWith("TextDecoration.combine")) {
    try {
      final start = key.indexOf('[');
      final end = key.lastIndexOf(']');
      final parts = key
          .substring(start, end + 1)
          .split(", ")
          .where((e) => e.isNotEmpty);
      return TextDecoration.combine(
        parts.map(parseTextDecoration).whereType<TextDecoration>().toList(),
      );
    } catch (_) {
      return null;
    }
  }
  return null;
}