我已经在flutter应用程序中下载了我需要的图标,并且在pubspec.yaml中指定了file.ttf的路径后,图标未显示在我的应用程序中
这是代码
import 'package:flutter/widgets.dart';
class CustomizedIcons{
static const IconData stock_type1 = const IconData(0xe900,fontFamily:
"iconication");
static const IconData stock_type2 = const IconData(0xe901,fontFamily:
"iconication");
static const IconData business_deal = const IconData(0xe902,fontFamily:
"iconication");
static const IconData sales_growth = const IconData(0xe903,fontFamily:
"iconication");
static const IconData sales_rep = const IconData(0xe904,fontFamily:
"iconication");
static const IconData alert = const IconData(0xe905,fontFamily:
"iconication");
static const IconData business_clients = const
IconData(0xe906,fontFamily: "iconication");
}
这是pubspec.yaml文件代码
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
fonts:
- family: iconication
fonts:
- asset: icons\ic_iconication.ttf
答案 0 :(得分:0)
您使用反斜杠而不是正斜杠:
icons\ic_iconication.ttf
应该是
icons/ic_iconication.ttf
我假设您已将ttf文件放在资产/图标目录中?
答案 1 :(得分:0)
这是一个古老的问题,但是我花了几个小时来寻找答案,很难找到。因此,这是帮助他人的解决方案。
在pubspec.yaml上,fonts
属性必须位于正确嵌套的flutter
下方和内部。
示例:
flutter:
fonts:
- family: iconication
fonts:
- asset: icons/ic_iconication.ttf