toPlainText static method

  1. @useResult
String? toPlainText(
  1. String? htmlText
)

Strips HTML tags and unescapes HTML entities in one operation.

Returns null if the input is null, empty, or tags-only.

Example:

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

Implementation

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