spooky-mb

Asset Generator

We use flutter_gen to get rid of all String-based APIs. To make things easier, flutter_gen will read all assets & fonts from pubspec.yaml and generate them into classes.

Usage

// String-based - bad practice
Image.asset('assets/images/profile.jpeg');
TextStyle(fontFamily: "Quicksand")

// Use this instead
Image.asset(Assets.images.profile.path);
Assets.images.profile.image()
TextStyle(fontFamily: FontFamily.quicksand)

Setup

For on macOS, Linux, and Windows.

# Installing
dart pub global activate flutter_gen

# To make sure it's installed
fluttergen

Generate

To generate, add needed assets or fonts in pubspec.yaml, then run fluttergen on your console.

flutter:
  ...
  assets:
    - assets/illustrations
    - assets/images

  # also work with fonts
  fonts:
    - family: Schyler
      fonts:
        - asset: fonts/Schyler-Regular.ttf
        - asset: fonts/Schyler-Italic.ttf
          style: italic
# From console
fluttergen