resources_generator 1.0.10
resources_generator: ^1.0.10 copied to clipboard
An resource class generator for Flutter, like Android resource class R.
Resource generator #
Feature #
Generate a resource class from assets/ folder, similar to R class on Android.
Configurations #
This generator supports generate common assets folder and assets folder divided by flavors.
Without flavor #
Required structure for assets folder:
<your-project>
├── <assets-folder>/
├── images/ (for images)
├── vectors/ (for vector images or svg)
├── translations/ (for localizations)
├── fonts/ (for fonts)
├── scripts/ (for shell scripts)
├── configs/ (for JSON configurations)
├── raws/ (for raw files)
├── lib/
├── pubspec.yaml
With flavor #
Required structure for assets folder:
<your-project>
├── <assets-folder>/
├── all/ <common for all flavors>
├── images/ (for images)
├── vectors/ (for vector images or svg)
├── translations/ (for localizations)
├── fonts/ (for fonts)
├── scripts/ (for shell scripts)
├── configs/ (for JSON configurations)
├── raws/ (for raw files)
├── <flavor-0>
├── ... (same as all/)
├── <flavor-1>
├── ... (same as all/)
├── <flavor-2>
├── ... (same as all/)
├── ...
├── lib/
├── pubspec.yaml
Usage #
Activate the executable:
dart pub global activate resources_generator
cd into project root:
cd <your-project>
Execute the generator:
dart pub global run resources_generator:generate -i <assets-folder> -o <output-folder> -p <optional-package> -f
or execute automatically when assets changes:
dart pub global run resources_generator:monitor -i <assets-folder> -o <output-folder> -p <optional-package> -f
with:
-ior--input, optional, is the input assets folder, default toassets.-oor--output, optional, is the output folder, default tolib/resources.-por--package, optional, is the package name if assets is in a package/module instead of an application..-for--with-flavor, optional, will generate the resource class into flavors.
Note #
-
For generating fonts, font file names must have this format:
<family>-<attr-1>-<attr-2>.ttf, with attrs to be font style and font weight. These attrs are optional.
Example: Roboto.ttf, Roboto-Italic.ttf, Roboto-Italic-w600.ttf -
For generating colors, all json files must have
colorsas file name prefix. Based on the numbers of file with this prefix, the generator will generate the suitable resource file.
Example:- For single file:
├── <assets-folder>/ ├── colors/ ├── colors.json - For multiple files (multi variants colors):
├── <assets-folder>/ ├── colors/ ├── colors_dark.json ├── colors_light.json
- For single file: