我找不到将ThemeFontFontFamily应用于appBar和FAB的方法。
鉴于我不想将其分别应用于小部件,如何实现?
这是ThemeData初始化
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
textTheme: Theme.of(context).textTheme.apply(
fontFamily: 'MaShanZheng',
),
),
这是结果
答案 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,textTheme
由button
小部件中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'),
);