我正在开发一个仅使用一种字体的应用程序。因此我在 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)