0

I've downloaded the icons that I need in my flutter app and after specifying the path to the file.ttf inside pubspec.yaml, Icons does not show up in my app

here is the code

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");

}

and here is the pubspec.yaml file code

 # 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
Karrar
  • 1,273
  • 3
  • 14
  • 30

2 Answers2

0

You have a backslash rather than a forward slash:

icons\ic_iconication.ttf

Should be

icons/ic_iconication.ttf

I am assuming you have put the ttf file in assets/icons directory?

GrahamD
  • 2,952
  • 3
  • 15
  • 26
  • I have a folder called icons and inside it i have the .ttf file , should I nest the icons folder inside a folder with name of assets ?? – Karrar Aug 12 '19 at 20:06
  • icons\ic_iconication.ttf – GrahamD Aug 12 '19 at 20:12
  • Sorry doing this on my phone. Flutter looks for assets in the assets subfolder of your project so the ttf file should be in yourprojectname/assets/icons – GrahamD Aug 12 '19 at 20:14
  • Actually I would probably put a ttf file in a fonts subfolder of assets, icons are normally png or jpg. – GrahamD Aug 12 '19 at 20:16
  • It still not working , I have put the ttf file in this pathway myproject/assets/fonts/ic_iconication.ttf – Karrar Aug 12 '19 at 20:46
  • Apologies for slow reply, had to go and sleep. I should ask what error messages you are seeing, if any. – GrahamD Aug 13 '19 at 06:21
  • I cannot find that ttf file on the Web so can't really test. If Flutter is finding the ttf file (ie. no error message) then it can only be your code or the contents of the ttf file. Your code looks OK as far as it goes but you don't show how you are trying to invoke the icon. See this answer https://stackoverflow.com/a/46102297/10376604 which seems to address what you need. – GrahamD Aug 13 '19 at 06:42
0

This is an old question but I spent a few hours searching for an answer and it was difficult to find. So here is the solution to help others.

On the pubspec.yaml the fonts property must be below and inside the flutter properly nested. Example:

flutter:
  fonts:
   - family: iconication
     fonts:
      - asset: icons/ic_iconication.ttf