如何在ThemeData中实现TextTheme

时间:2020-08-07 11:52:36

标签: flutter dart

我正在尝试为整个应用程序使用不同的文件,然后在main.dart文件中调用该函数。

ThemeData appTheme1() {
  const colorBlack = const Color(0xFF4C4B4B);
  const colorWhite = const Color(0xFFDAE0E2);
  const colorGrey = const Color(0xFF7B8788);
  return ThemeData(
    primaryColor: colorBlack,
    accentColor: colorWhite,
    // hintColor: Colors.white,
    // dividerColor: Colors.white,
    buttonColor: colorBlack,
    scaffoldBackgroundColor: colorWhite,
    // canvasColor: Colors.black,
    fontFamily: "NanumMyeongjo",
  );
}

问题是如何在此ThemeData中添加文本样式? 谢谢。

2 个答案:

答案 0 :(得分:0)

使用textTheme属性:我使用您的代码添加了一个示例:

ThemeData appTheme1() {
  const colorBlack = const Color(0xFF4C4B4B);
  const colorWhite = const Color(0xFFDAE0E2);
  const colorGrey = const Color(0xFF7B8788);
  return ThemeData(
    primaryColor: colorBlack,
    accentColor: colorWhite,
    // hintColor: Colors.white,
    // dividerColor: Colors.white,
    buttonColor: colorBlack,
    scaffoldBackgroundColor: colorWhite,
    // canvasColor: Colors.black,
    fontFamily: "NanumMyeongjo",
    // use the textTheme property
    textTheme: TextTheme().copyWith(
      headline1:  TextStyle(
        // add your styles
      ),
    ),
  );
}

答案 1 :(得分:0)

您是否尝试过Stylist包裹? (https://pub.dev/packages/stylist)。使用它更容易,更清洁地应用主题。