SOLUTION FOUND:
Using Android Studio solved the issue !! I ran the app using Android Studio and everything worked fine! It looks like VSCode did not cope well with Custom Fonts. Therefore I would advise using Android Studio when somebody needs to add custom fonts
我正在尝试在我的应用程序中使用名为“Great Vibes”的Google字体 .
这就是我做的:
-
我在根文件夹中创建了一个"fonts"目录
-
我在该目录中复制了"GreatVibes-Regular.ttf"文件(从Google Fonts网站下载)
-
我在pubspec.yaml中引用了它(见下文)
-
当我想使用它时,我在TextStyle中引用它
结果:未使用该字体 .
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,
)),
没有报告错误 . 我也通过_1715146验证了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"
}
}
}
我也尝试从设备中删除应用程序并重新安装它,但没有任何变化 .
你有什么想法吗?
谢谢
扑医生-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.
1 回答
发生错误是因为pubspec.yaml没有自动保存,因此在运行get包之前,关闭pubspec.yaml文件并手动保存,再次运行get packages,它现在应该解决问题 .
此解决方案适用于Android Studio和VSCode .