RichText
RichText参考:RichTextTextSpanRichText表示的是富文本,使用不同的样式来显示文本,使用TextSpan对象来描述要显示的文本Text displayed in a RichText widget must be explicitly styled. When picking which style to use, consider using Defa...
·
RichText
参考:
RichText表示的是富文本,使用不同的样式来显示文本,使用TextSpan对象来描述要显示的文本
Text displayed in a
RichTextwidget must be explicitly styled. When picking which style to use, consider usingDefaultTextStyle.of the currentBuildContextto provide defaults. For more details on how to style text in a RichText widget, see the documentation for TextStyle.
RichText中的text需要显式指定样式。可考虑使用BuildContext的DefaultTextStyle来提供默认样式
TextSpan构造方法
TextSpan({String text List<InlineSpan> children, TextStyle style, GestureRecognizer recognizer, String semanticsLabel })
如下的例子:
class ContainerWithBoxDecorationWidget extends StatelessWidget {
const ContainerWithBoxDecorationWidget({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Container(
height: 100.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(100.0),
bottomRight: Radius.circular(10.0),
),
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.white,
Colors.lightGreen.shade500,
],
),
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 10.0,
offset: Offset(0.0, 10.0),
)
],
),
child: Center(
child: RichText(
text: TextSpan(
text: 'Flutter World',
style: TextStyle(
fontSize: 24.0,
color: Colors.deepPurple,
decoration: TextDecoration.underline,
decorationColor: Colors.deepPurpleAccent,
decorationStyle: TextDecorationStyle.dotted,
fontStyle: FontStyle.italic,
fontWeight: FontWeight.normal,
),
children: [
TextSpan(
text: ' for',
),
TextSpan(
text: ' Mobile',
style: TextStyle(
color: Colors.deepOrange,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal
)
),
]
),
),
),
),
],
);
}
}
效果如下:

更多推荐

所有评论(0)