Daassets

A Dart package to automatically generate a class containing references to all assets in your project.

Installation

Add the following dependencies to your pubspec.yaml:

dev_dependencies:
  daassets: ^1.5.0

Example

Define your assets

In your pubspec.yaml file:

flutter:

  assets:

    - assets/icon/            # imports all files in that directory
    - assets/icon/close.png   # imports that specific file

Generating Dart code

To generate the Dart file containing all assets, run the following command:

flutter pub run daassets:daassets.dart PUBSPEC_FILE_PATH OUTPUT_FILE_PATH

For example:

flutter pub run daassets:daassets.dart ./pubspec.yaml ./lib/assets.dart

Using generated code

The generated class contains static constants that you can use anywhere in your project.

Image.asset(Assets.ICON_CLOSE);

Libraries

daassets