找到的解决方案:
使用 Android Studio 解决了这个问题!我使用 Android Studio 运行该应用程序,一切正常!看起来 VSCode 不能很好地处理自定义字体。因此,当有人需要添加自定义字体时,我建议使用 Android Studio
我正在尝试在我的应用程序中使用名为“Great Vibes”的 Google 字体。
这就是我所做的:
结果:未使用该字体。
fonts:
- family: GreatVibes
fonts:
- asset: fonts/GreatVibes-Regular.ttf
weight: 400
new Text('My New Font',
style: new TextStyle(
color: Colors.white,
fontFamily: 'GreatVibes',
fontSize: 16.0,
)),
Run Code Online (Sandbox Code Playgroud)
没有报告错误。我还通过在线 YAML 解析器验证了 yaml 这是输出:
{
"description": "My app",
"dependencies": {
"http": "^0.11.3+16",
"shared_preferences": "^0.4.0",
"url_launcher": "^2.0.0",
"cupertino_icons": "^0.1.0",
"image_picker": "^0.4.1",
"flutter_facebook_login": "^1.0.3",
"flutter_localizations": {
"sdk": "flutter"
},
"carousel_slider": "^0.0.4",
"connectivity": "^0.3.0",
"device_info": "^0.1.2",
"intl": "^0.15.5",
"font_awesome_flutter": "^7.0.0",
"scoped_model": "^0.2.0",
"flutter": {
"sdk": "flutter"
},
"flutter_webview_plugin": "^0.1.4"
},
"flutter": {
"fonts": [
{
"fonts": [
{
"asset": "fonts/GreatVibes-Regular.ttf",
"weight": 400
}
],
"family": "GreatVibes"
}
],
"assets": [
"images/avatar.png",
"images/logo.png"
]
},
"name": "my_app",
"dev_dependencies": {
"flutter_test": {
"sdk": "flutter"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我还尝试从设备中删除该应用程序并重新安装它,但没有任何变化。
你有什么想法吗?
谢谢
颤振医生 -v
[?] Flutter (Channel beta, v0.4.4, on Microsoft Windows [Version 10.0.17134.112], locale en-US)
• Flutter version 0.4.4 at d:\flutter
• Framework revision f9bb4289e9 (5 weeks ago), 2018-05-11 21:44:54 -0700
• Engine revision 06afdfe54e
• Dart version 2.0.0-dev.54.0.flutter-46ab040e58
[?] Android toolchain - develop for Android devices (Android SDK 27.0.3)
• Android SDK at C:\Users\boeledi\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-27, build-tools 27.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
• All Android licenses accepted.
[?] Android Studio (version 3.1)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 25.0.1
• Dart plugin version 173.4700
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
[!] VS Code, 64-bit edition (version 1.24.0)
• VS Code at C:\Program Files\Microsoft VS Code
• Dart Code extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code
[?] Connected devices (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 8.1.0 (API 27) (emulator)
! Doctor found issues in 1 category.
Run Code Online (Sandbox Code Playgroud)
Sur*_*gch 11
OP 表示他们解决了他们的问题。这是对未来读者的一般性回答。
assets。它应该在您的项目根目录中。assets目录中。在我的示例中,我只使用了一种字体,即常规的跳舞脚本字体。我将其重命名为dancing_script.ttf.在该flutter部分下添加字体信息。缩进是强制性的。
flutter:
fonts:
- family: DancingScript
fonts:
- asset: assets/dancing_script.ttf
Run Code Online (Sandbox Code Playgroud)现在,您可以通过将小部件中的fontFamily属性设置为TextStyle您在 pubspec.yaml 中调用的任何内容来使用您的字体。对于这个例子,我称之为DancingScript。
Text(
'Hello world',
style: TextStyle(
fontFamily: 'DancingScript',
),
)
Run Code Online (Sandbox Code Playgroud)小智 1
发生错误的原因是 pubspec.yaml 没有自动保存,因此在运行 get packages 之前,关闭 pubspec.yaml 文件并手动保存,再次运行 get packages,现在应该可以解决问题。
该解决方案适用于 Android Studio 和 VSCode。
| 归档时间: |
|
| 查看次数: |
6899 次 |
| 最近记录: |