如何在Flutter中定义自定义文本主题? [英] How to define custom text theme in flutter?
问题描述
如何制作自己的文字主题样式? 我只能找到这样的默认文本主题,但这还不够.
How to make my own text theme style? I only find the default text theme like this but it's not enough.
textTheme: TextTheme(
body1: TextStyle(),
body2: TextStyle(),
button: TextStyle(),
caption: TextStyle(),
display1: TextStyle(),
display2: TextStyle(),
display3: TextStyle(),
display4: TextStyle(),
headline: TextStyle(),
overline: TextStyle(),
subhead: TextStyle(),
subtitle: TextStyle(),
title: TextStyle(),
),
例如,我想要一个带有直行的文本,然后另一些带有下划线的文本
我当时正在考虑为下划线样式覆盖body2
,然后如何为通过下划线定义另一种样式?
I want for example have a text with line through then some other have underline etc
I was thinking to override the body2
for underline style then how to define another style for line through?
亲切的问候
推荐答案
您可以创建一个类来保存您的样式,然后从应用程序中的任何位置调用它.
You can create a class to hold your style and then call it from anywhere in your app.
class CustomTextStyle {
static TextStyle display5(BuildContext context) {
return Theme.of(context).textTheme.display4.copyWith(fontSize: 192.0);
}
}
并将其用作
Text(
'Wow',
style: CustomTextStyle.display5(context),
),
查看问题 Flutter:定义自定义TextStyle,以在整个应用程序中使用,其中包含此处引用的完整答案.
Look at question Flutter: Define custom TextStyles for use throughout the app that contains the complete answer referred here.
这篇关于如何在Flutter中定义自定义文本主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!