icon_fonts在我的Flutter应用中不起作用

时间:2019-08-09 17:00:11

标签: flutter icon-fonts

我已经在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

2 个答案:

答案 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