Sam*_*827 3 fonts dart flutter
我正在开发一个仅使用一种字体的应用程序。因此我在 main.dart 文件中设置了默认字体。
return MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
debugShowCheckedModeBanner: false,
theme: ThemeData(
fontFamily: 'Diodrum',
textSelectionTheme: const TextSelectionThemeData(
cursorColor: lrBlue, //<-- SEE HERE
),
),
title: "Hello",
Run Code Online (Sandbox Code Playgroud)
然而,我注意到有时在像 RichText/TextSpan 这样的小部件上,小部件会忽略字体,而是使用 Flutter 默认字体(Roboto?)。例如,在我的登录页面上:
RichText(
text: TextSpan(
text: 'Not a member yet? ',
style: const TextStyle(
color: lrDarkBlue,
fontSize: 12,
fontWeight: FontWeight.w500,
),
children: <TextSpan>[
TextSpan(
text: 'Sign up!',
style: const TextStyle(
color: lrMediumBlue,
fontSize: 12,
fontWeight: FontWeight.w700,
decoration: TextDecoration.underline,
),
recognizer: TapGestureRecognizer()
..onTap = () {
Navigator.pushNamed(context, '/signup');
},
),
],
),
),
Run Code Online (Sandbox Code Playgroud)
这就是结果。该按钮具有正确的字体,但其下方的文本不正确。
我通过手动指定字体和文本更改为正确的字体来测试它。但默认情况下它会忽略 ThemeData 中设置的默认字体。
这是否只是 RichText/TextSpan 的问题,我必须为这些小部件手动指定它,还是它是一个错误并且不应该发生?
pow*_*rus 14
要申请RichText
默认值TextStyle
,只需使用Text.rich
:
Text.rich(
TextSpan(
children: [
TextSpan(text: 'Aloha '),
TextSpan(
text: ' my friend',
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1072 次 |
最近记录: |