toPlainText static method
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 & World</p>'); // 'Hello & World'
HtmlUtils.toPlainText('<script>'); // '<script>'
Implementation
static String? toPlainText(String? htmlText) {
final String? stripped = removeHtmlTags(htmlText);
if (stripped == null) {
return null;
}
return unescape(stripped);
}