5

I am trying to import custom icons from Fluttericons.com. I get a box with an X within it instead of the icon as shown in the image. I have included my pubspec.yaml and dart file that is given from Fluttericons.com.

Screenshot of bad icons

Workspace screenshot

This is the Fluttericons.com file given to me. I have tried to remove the _kFontPkg and that did not work.

import 'package:flutter/widgets.dart';

class MyIcons {
  MyIcons._();

  static const _kFontFam = 'MyIcons';
  static const _kFontPkg = null;

  static const IconData access_alarm = IconData(0xe800, fontFamily: _kFontFam, fontPackage: _kFontPkg);
}
name: MyGymPro
description: Flutter fitness application

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_icons:
  percent_indicator: "^2.1.1"
  pedometer: ^1.0.0
  intl: ^0.16.1
  auto_size_text: ^2.1.0
  shared_preferences: any
  http: ^0.12.0+4
  font_awesome_flutter: ^8.4.0
  decimal: ^0.3.3
  image_picker: ^0.6.4
  mime: ^0.9.6+3
  fluttertoast: ^4.0.0


  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter


flutter:

  uses-material-design: true
  fonts:
   - family: MyIcons
     fonts:
       - asset: fonts/MyIcons.ttf

  # To add assets to your application, add an assets section, like this:
  assets:
    - assets/

Also, I am using Visual Studio.

1
  • Did you fix this? I'm also running into the same issue. Tried restarting the emulator, created a new emulator, restarted studio, restarted entire machine etc. Nothing works. It shows a rectangle shape only. Commented Nov 23, 2020 at 18:39

2 Answers 2

1

check where you keep the font file,

  • asset: fonts/MyIcons.ttf

maybe you save it in

  • asset: assets/fonts/MyIcons.ttf

if your min sdk not 2.12.0, i mean not supported null safety, remove non null safety at this line static const? _kFontPkg = null;. not recommended this.

and then if icon not show just blank, unistall your app from emulator, and run again.

Sign up to request clarification or add additional context in comments.

Comments

0

Whenever you add a dependency you should make sure that you have shutdown and restart your emulator.

3 Comments

what is your exit code when you save your pubspec.yaml file
exit code 0, there is no error in the debug console and everything runs smoothly.
Tried restarting and even tried with new emulator. Nothing works. Any other idea?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.