我一直在使用自定义TextStyle
,并将字体文件保存在myApp / fonts /中,并且运行良好。
但是,在我将ThemeData
添加到我的应用程序之后,自定义TextStyle
无法正常工作,它们似乎还需要其他weight
。我为自定义TextStyle
和ThemeData
使用了相同的文本字体,唯一的区别是字体大小。我还需要使用自定义TextStyle
,因为我需要的字体大小比预设的5个标题和2个字幕和2个ThemeData
的bodyTexts要多。
请问有人有想法吗?
pubspec:
flutter:
fonts:
- family: Baskerville
fonts:
- asset: fonts/Baskerville.ttc
- family: Futura
fonts:
- asset: fonts/Futura.ttc
- family: Tinos
fonts:
- asset: fonts/Tinos-Italic.ttf
style: italic
- asset: fonts/Tinos-BoldItalic.ttf
weight: 700
uses-material-design: true
我的主题数据:
class MyPortfolio extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primaryColor: Colors.grey[900],
accentColor: Colors.grey[900],
fontFamily: 'Futura',
textTheme: TextTheme(
headline1: TextStyle(fontSize: 48),
headline2: TextStyle(fontSize: 40),
headline3:
TextStyle(fontSize: 40, decoration: TextDecoration.underline),
headline4: TextStyle(fontSize: 30),
headline5: TextStyle(fontSize: 13),
subtitle1: TextStyle(fontSize: 25),
subtitle2: TextStyle(fontSize: 13, fontFamily: 'Baskerville'),
bodyText1: TextStyle(
fontSize: 15,
fontFamily: 'Tinos',
fontStyle: FontStyle.italic,
color: Colors.grey),
bodyText2: TextStyle(
fontSize: 15,
fontFamily: 'Tinos',
fontWeight: FontWeight.w700,
color: Colors.grey),
),
),
);
}
}
我的代码:
class IntroSection extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
...
child: Container(
child: Text.rich(
TextSpan(
text: 'People say xxx is ',
style: Theme.of(context).textTheme.headline2,
children: <TextSpan>[
TextSpan(
text: '...',
style:
Theme.of(context).textTheme.headline3)),
...
Container(
child: Text.rich(
TextSpan(
text: 'And I am actually an ',
style: TextStyle(
fontFamily: 'Futura',
fontSize: 40,
color: Color.fromRGBO(40, 46, 49, 100)),
children: <TextSpan>[
TextSpan(
text: 'artist-designer ',
style: TextStyle(
fontFamily: 'Futura',
fontStyle: FontStyle.italic)),
...
}
}