有几个html文件和一个css文件是从所有的html中使用的。我使用了flutter_html库,html文件正常显示,但没有css。
是否有办法"import"css文件,因为它是没有转换成Dart
?
下面是css文件的一部分。这很简单。如果不能导入,那么翻译成Dart
代码的最好方法是什么?
body {... margin-right:20; margin-bottom: 3 ...}
table {... margin-bottom: 3}
h1 {...}
h2 {font-family: 'palatino linotype'...}
h3 {...}
p:first-letter {...}
body {...}
尝试使用这个库它也可以识别CSS
然后你可以使用你的CSS作为内联样式
String htmlContent =
"""
<p>This has no font size css property, but global style will be applied</p>
<a style='color: orange;'>The inline color for this is orange, but it will
get overridden by global style defined below</a>
""";
HTML.toTextSpan(
context,
htmlContent,
overrideStyle: {
"p": TextStyle(fontSize: 17.3),
"a": TextStyle(color: Colors.red),
// specify any tag not just the supported ones,
// and apply TextStyles to them and/override them
},
);