defaultRichAttributeStyle function

TextStyle defaultRichAttributeStyle(
  1. Map<String, Object?> attributes
)

The default RichAttributeStyle.

Reads bold, italic, underline and strike (booleans), link (any value, painted blue and underlined), color ('#rrggbb') and size (a number).

Implementation

TextStyle defaultRichAttributeStyle(Map<String, Object?> attributes) {
  final link = attributes['link'];
  final color = attributes['color'];
  final size = attributes['size'];
  final decorations = <TextDecoration>[
    if (attributes['underline'] == true || link != null)
      TextDecoration.underline,
    if (attributes['strike'] == true) TextDecoration.lineThrough,
  ];
  return TextStyle(
    fontWeight: attributes['bold'] == true ? FontWeight.bold : null,
    fontStyle: attributes['italic'] == true ? FontStyle.italic : null,
    decoration:
        decorations.isEmpty ? null : TextDecoration.combine(decorations),
    color: link != null
        ? const Color(0xFF1565C0)
        : color is String && _hexColor.hasMatch(color)
            ? Color(0xFF000000 | int.parse(color.substring(1), radix: 16))
            : null,
    fontSize: size is num ? size.toDouble() : null,
  );
}