icon_font_generator 0.0.7

Flutter Icon Font Generator #

Pub

Convert all *.svg icons from dir to icon-font (.ttf) and generates flutter compatible dart class.

Abstraction layer for NodeJs package icon-font-generator

Requirements #

Node.JS v11+

Install: #

$ pub global activate icon_font_generator

Params: #

* - required

  • --from * - Input dir with svg's
  • --out-font * - Output icon font path (to file, for example: lib/font.ttf)
  • --out-flutter * - Output flutter icon class (to file, for example: lib/icons.dart)
  • --class-name * - The class name is also the font name used in pubspec.yaml (as font name)
  • --height - Fixed font height value, defaults: 512
  • --ascent - Offset applied to the baseline, defaults: 240
  • --package - Name of package for generated icon data (See more)
  • --indent - Indent for generating dart file, for example: ' ', default: ' '
  • --mono - Make font monospace, default: true

Example #

File structire:

project
└───icons
│   │   account.svg
│   │   arrow_left.svg
│   │   arrow_right.svg
│   │   collection.svg
│   
└───lib
│   │   icon_font
│   │   widgets

Run command:

$ icon_font_generator --from=icons --class-name=UiIcons --out-font=lib/src/icon_font/ui_icons.ttf --out-flutter=lib/src/widgets/icons.dart

Generated to:

project
└───icons
│   │   account.svg
│   │   arrow_left.svg
│   │   arrow_right.svg
│   │   collection.svg
│   
└───lib
│   └───widgets
│   |   │   icons.dart
│   │
│   └───icon_font
│       │   ui_icons.ttf

Generated icons.dart:

import 'package:flutter/widgets.dart';

@immutable
class UiIconsData extends IconData {
  const UiIconsData(int codePoint)
      : super(
          codePoint,
          fontFamily: 'UiIcons',
        );
}

@immutable
class UiIcons {
  UiIcons._();

  // Generated code: do not hand-edit.
  static const IconData account = UiIconsData(0xe000);

  static const IconData arrowLeft = UiIconsData(0xe001);

  static const IconData arrowRight = UiIconsData(0xe002);

  static const IconData collection = UiIconsData(0xe003);
}

And also need add font to pubspec.yaml:

...

flutter:
  fonts:
    - family: UiIcons
      fonts:
        - asset: lib/src/icon_font/ui_icons.ttf

Still you can usage it with DPM (Dart Package Manager)

For example:

  1. $ pub global activate dpm
  2. $ dpm add --dev icon_font_generator
  3. Next add script to pubspec.yaml:
...
scripts:
  generate_icons: icon_font_generator 
    --from=icons 
    --class-name=UiIcons 
    --out-font=lib/icon_font/ui_icons.ttf 
    --out-flutter=lib/widgets/icons.dart
  1. And always perform with the command: dpm generate_icons

0.0.7 #

  • Update requirements in readme

0.0.6 #

  • Update requirements in readme

0.0.5 #

  • Update readme

0.0.4 #

  • Readme fix

0.0.3 #

  • Hide error message

0.0.2 #

  • Fix running as global package

0.0.1 #

  • Initial release

example/README.md

Example #

File structire:

project
└───icons
│   │   account.svg
│   │   arrow_left.svg
│   │   arrow_right.svg
│   │   collection.svg
│   
└───lib
│   │   icon_font
│   │   widgets

Run command:

$ icon_font_generator --from=icons --class-name=UiIcons --out-font=lib/icon_font/ui_icons.ttf --out-flutter=lib/widgets/icons.dart

Generated to:

project
└───icons
│   │   account.svg
│   │   arrow_left.svg
│   │   arrow_right.svg
│   │   collection.svg
│   
└───lib
│   └───widgets
│   |   │   icons.dart
│   │
│   └───icon_font
│       │   ui_icons.ttf

Generated icons.dart:

import 'package:flutter/widgets.dart';

@immutable
class UiIconsData extends IconData {
  const UiIconsData(int codePoint)
      : super(
          codePoint,
          fontFamily: 'UiIcons',
        );
}

@immutable
class UiIcons {
  UiIcons._();

  // Generated code: do not hand-edit.
  static const IconData account = UiIconsData(0xe000);

  static const IconData arrowLeft = UiIconsData(0xe001);

  static const IconData arrowRight = UiIconsData(0xe002);

  static const IconData collection = UiIconsData(0xe003);
}

And also need add font to pubspec.yaml:

...

flutter:
  fonts:
    - family: UiIcons
      fonts:
        - asset: lib/icon_font/ui_icons.ttf

Still you can usage it with DPM (Dart Package Manager)

For example:

  1. $ pub global activate dpm
  2. $ dpm add --dev icon_font_generator
  3. Next add script to pubspec.yaml:
...
scripts:
  generate_icons: icon_font_generator 
    --from=icons 
    --class-name=UiIcons 
    --out-font=lib/icon_font/ui_icons.ttf 
    --out-flutter=lib/widgets/icons.dart
  1. And always perform with the command: dpm generate_icons

Use this package as an executable

1. Install it

You can install the package from the command line:


$ pub global activate icon_font_generator

2. Use it

The package has the following executables:


$ icon_font_generator

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  icon_font_generator: ^0.0.7

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:icon_font_generator/generate_flutter_class.dart';
import 'package:icon_font_generator/templates/flutter_icons.dart';
import 'package:icon_font_generator/templates/npm_package.dart';
import 'package:icon_font_generator/utils.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
37
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
66
Learn more about scoring.

We analyzed this package on Aug 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, other

Platform components identified in package: io.

Health issues and suggestions

Document public APIs. (-1 points)

15 out of 15 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/templates/npm_package.dart.

Run dartfmt to format lib/templates/npm_package.dart.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0-dev.0.5 <3.0.0
args ^1.5.2 1.5.2
meta ^1.1.6 1.1.7
path ^1.6.4 1.6.4
register ^1.0.1 1.0.1
Transitive dependencies
collection 1.14.12
matcher 0.12.5
quiver 2.0.5
stack_trace 1.9.3
Dev dependencies
pedantic ^1.5.0