颤振如何将FontFamily从ThemeData应用于AppBar和FAB

时间:2020-01-01 12:07:16

标签: flutter

我找不到将ThemeFontFontFamily应用于appBar和FAB的方法。

鉴于我不想将其分别应用于小部件,如何实现?

这是ThemeData初始化

    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        textTheme: Theme.of(context).textTheme.apply(
            fontFamily: 'MaShanZheng',
        ),
      ),

这是结果

enter image description here

1 个答案:

答案 0 :(得分:3)

这就是您为AppBar做的方式。

MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
              textTheme: TextTheme(title: ,button: ),
              appBarTheme: AppBarTheme(
                  textTheme: TextTheme(
                      title: TextStyle(
                          fontFamily://your font family
                          fontWeight: FontWeight.bold,
                          fontStyle: FontStyle.italic)))),
          home:Home(),
        );

对于FAB,textThemebutton小部件中accentTextTheme参数的ThemeData参数决定。

即。

return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        accentTextTheme:TextTheme(button:TextStyle(fontSize:63),),
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );