toPlainText static method

String? toPlainText(
  1. String? htmlText
)

Strips HTML tags and unescapes HTML entities in one operation.

Combines removeHtmlTags and unescape for convenience when you need to convert HTML content to plain text.

Returns null if:

  • The input is null or empty
  • The result after processing is empty

Example:

HtmlUtils.toPlainText('<p>Hello &amp; World</p>'); // 'Hello & World'
HtmlUtils.toPlainText('&lt;script&gt;'); // '<script>'

Implementation

static String? toPlainText(String? htmlText) {
  final String? stripped = removeHtmlTags(htmlText);
  if (stripped == null) {
    return null;
  }
  return unescape(stripped);
}