小编Sam*_*827的帖子

RichText 覆盖默认字体系列

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

fonts dart flutter

3
推荐指数
1
解决办法
1072
查看次数

标签 统计

dart ×1

flutter ×1

fonts ×1