首页 > 解决方案 > 如何在颤动中覆盖主题样式

问题描述

嗨,我需要文本样式,例如bodyText3,像这样

 bodyText3: TextStyle(
            fontSize: 16,
            height: 1.5,
            fontWeight: FontWeight.w600,
            color: MyColors.black)

但在颤振中,我们只有这种风格。

headline1,
headline2,
headline3,
headline4,
headline5,
headline6,
subtitle1,
subtitle2,
bodyText1,
bodyText2,
caption,

我应该怎么做才能添加我的新风格?

标签: flutter

解决方案


创建一个常量来定义样式

const TextStyle bodyText3 = TextStyle(
  fontSize: 14,
  color: darkGrey,
  fontWeight: FontWeight.w700,
);

在 Text 的 style 属性中使用此常量

 Text(
   'No',
   style: bodyText3,
),

推荐阅读