我需要在 flutter 应用程序中将 HTML 和 CSS 呈现为 Flutter 小部件。我从 API 得到了输入。我想先检查我得到的输入是否是 HTML 格式。
此功能检查您的输入是否为 HTML 格式。
bool isHTML(String str) {
final RegExp htmlRegExp =
RegExp('<[^>]*>', multiLine: true, caseSensitive: false);
return htmlRegExp.hasMatch(str);
}
例子
String input =
"<p>Flutter is an open source framework by Google for building beautiful, natively compiled, multi-platform applications from a single codebase.</p>";
bool isInHTMLFormat = Validator.isHTML(input); // output true
基于此,我们可以借助Flutter_html
显示 HTML 内容