这是给您的代码...我在此代码中使用了CSS_TEXT包
import 'package:flutter/material.dart';
import 'package:css_text/css_text.dart';
void main() {
runApp(MaterialApp(
title: 'Androidmonks',
home: Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
backgroundColor: Colors.orangeAccent,
floating: true,
actions: <Widget>[
_Home(),
],
),
],
),
)));
}
class _Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
String htmlContent = """
<body>
<p style="font-size:1.5em;">
Hello <b style="font-style:italic;color:#bb0000;background:#eeff00">World</b>!!
<br/>
How are you <span style="font-family:RobotoBlack;color:#ff0000;">today?</span>
<br/>
<b>But</b> why are you doing <a href="https://google.com">this?</a><br/>
<br/>
<span style="text-decoration: underline wavy; font-size:2em">Can you tell <del>me</del>?</span>
<br/>
Please visit <a style="font-weight:bold;" href="https://docs.flutter.io">Flutter docs</a>
<br/>
<br/>
<span style="color:#990000ff;background:#4400ff00">
This text is slightly transparent, and has a slightly transparent background too.
</span>
</p>
</body>
""";
var myRichText =
HTML.toRichText(context, htmlContent, linksCallback: (link) {
print("You clicked on $link");
});
return Scaffold(
body: Container(padding: EdgeInsets.all(16.0), child: myRichText));
}
}
//
// }}
我运行了此代码,但是它显示了白色的空白屏幕,没有任何类型的错误
[请帮助我解决此错误????
它可以正常工作,并且可以在我的手机上运行,但屏幕上什么也没有出现。只有白屏。请更正我的代码
这里是您的重要信息
Consider applying a flex factor (e.g. using an Expanded widget) to force the
children of the RenderFlex to fit within
the available space instead of being sized to their natural size.
This is considered an error condition because
it indicates that there is content that cannot be seen.
If the content is legitimately
bigger than the available space,
consider clipping it with a ClipRect widget
before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView.
我相信您在这里的唯一问题是,您不应在另一个支架内的SliverAppbar内返回支架。
因此您可以切换以下行:
return Scaffold(
body: Container(padding: EdgeInsets.all(16.0), child: myRichText));
为此:
return Container(padding: EdgeInsets.all(16.0), child: myRichText));