flutter - 在 Flutter 中添加自定义字体时遇到问题
问题描述
在 Flutter 中添加自定义字体时我没有收到错误,但它没有应用字体。
我已经尝试了完全重建、重新安装以及从其他类似线程中读取的内容,但到目前为止没有任何效果。这是我的 pubspec.yaml 的一部分
flutter:
uses-material-design: true
fonts:
- family: Bauhaus
fonts:
- asset: fonts/Bauhaus.ttf
这是一个代码示例...
new TextSpan(
text: 'Started!',
style: new TextStyle(
decoration: TextDecoration.none,
fontSize: 50.0,
fontFamily: "Bauhaus",
color: Colors.red,
),
),
它适用于“Times New Roman”等默认字体,但不适用于自定义字体。
解决方案
运行主功能后你还没有配置主题
像这样:
fonts:
- family: SFUIText
fonts:
- asset: assets/fonts/SFUIText-Regular.ttf
- asset: assets/fonts/SFUIText-Semibold.ttf
weight: 600
- asset: assets/fonts/SFUIText-RegularItalic.ttf
style: italic
final app = MaterialApp(
theme: ThemeData(
primaryIconTheme: const IconThemeData(color: mColorIcon),
primaryColor: mColorPrimary,
accentColor: mColorAccent,
backgroundColor: mColorBackground,
indicatorColor: mColorPrimary,
splashColor: mColorPrimary,
canvasColor: mColorCanvas,
appBarTheme: Styles.appBar,
fontFamily: 'SFUIText',
textTheme: TextTheme(
title: Styles.title,
body1: Styles.textSecondary,
body2: Styles.textSecondaryBold,
headline: Styles.headline,
subhead: Styles.subHeading,
button: Styles.button,
overline: Styles.overline)), ...);
推荐阅读
- sql - 对表的每一行逐一进行特定查询
- laravel - Laravel - 在调用另一个函数的函数中使用请求
- node.js - 剧作家隐身
- terraform - 进行 terraform destroy 时无法解码当前后端配置错误
- c# - C# 异步 REST 查询不起作用:WaitAll 或 WhenAll 结合 .Result 挂起
- python - 在 textinfo 注释内进行情节更改
- php - 有没有办法在不引用 PHP 的情况下复制数组?
- elasticsearch - Elasticsearch:我们开始使用 elasticsearch 高级客户端后 CPU 使用率高的模式
- laravel - 在 laravel 中安装身份验证
- c# - 根据半径计算球心,两点