- Notifications
You must be signed in to change notification settings - Fork21
Generate an R file for mapping all assets. Supports preview of image.
License
fluttercandies/flutter_asset_generator
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
English |中文文档
Automatically generate the dart file for pubspec.yaml
The purpose of this library is to help flutter developersautomatically generate asset corresponding dart filesto help developers release their hands from this meaningless job,and the open source community has a lot of the same functionality.
This library is based on dartlang's build library.
Adddart
to your$PATH
environment.
git clone https://github.com/fluttercandies/flutter_asset_generatorcd flutter_asset_generatordart pub getdart bin/asset_generator.dart$flutter_project
- Install usingpub global:
dart pub global activate flutter_asset_generator# ordart pub global activate -s git https://github.com/fluttercandies/flutter_asset_generator.git
- Run below commands:
fgen
orfgen -s $flutter_project
Use$ fgen -h
or$ fgen --help
see usage document.
fgen -h-w, --[no-]watch Continue to monitor changes after execution of orders. (defaults to on)-p, --[no-]preview Generate file with preview comments. (defaults to on)-o, --output Your resource file path. If it's a relative path, the relative flutter root directory (defaults to "lib/const/resource.dart")-s, --src Flutter project root path (defaults to ".")-n, --name The class name for the constant. (defaults to "R")-h, --[no-]help Help usage-d, --[no-]debug debug info
Space
, '.' and '-' in the path will be converted to_
.@
will be converted to_AT_
.
convert filed name example:
images/1.png => IMAGES_PNGimages/hello_world.jpg => IMAGES_HELLO_WORLD_JPGimages/hello-world.jpg => IMAGES_HELLO_WORLD_JPG
Errors will occur in the following situations:
images/├── main_login.png├── main/ ├── login.png
Because the two field names will be exactly the same.
The location of the configuration file is conventional.Configuration via commands isnot supported.The specified path isfgen.yaml
in the flutter project root directory.
InstallYAML Support plugin.
Config your vscodesettings.json
file.
It can be used to prompt the configuration file.
{"yaml.schemas": {"https://raw.githubusercontent.com/fluttercandies/flutter_asset_generator/master/fgen_schema.json": ["fgen.yaml"] }}
The file is yaml format, every element isglob
style.
The name of the excluded file is under theexclude
node, and the type is a string array. If no rule is included, it means no file is excluded.
Theinclude
node is the name of the file that needs to be imported, and the type is a string array. If it does not contain any rules, all file are allowed.
In terms of priority, exclude is higher than include, in other words:
First import the file according to the include nodes, and then exclude the files.
File names can be replaced according to the configuration file as shown below:
replace: -from:“to: -from:”to: -from:’to: -from:(to: -from:)to: -from:"!"to:
exclude: -"**/add*.png" -"**_**"include: -"**/a*.png" -"**/b*" -"**/c*"
assets├── address.png# exclude by "**/add*.png"├── address@at.png# exclude by "**/add*.png"├── bluetoothon-fjdfj.png├── bluetoothon.png└── camera.pngimages├── address space.png# exclude by "**/add*.png"├── address.png# exclude by "**/add*.png"├── addto.png# exclude by "**/add*.png"├── audio.png├── bluetooth_link.png# exclude by **_**├── bluetoothoff.png├── child.png└── course.png
/// Generate by[asset_generator](https://github.com/fluttercandies/flutter_asset_generator) library./// PLEASE DO NOT EDIT MANUALLY.classR {constR._();/// staticconstStringASSETS_BLUETOOTHON_FJDFJ_PNG='assets/bluetoothon-fjdfj.png';/// staticconstStringASSETS_BLUETOOTHON_PNG='assets/bluetoothon.png';/// staticconstStringASSETS_CAMERA_PNG='assets/camera.png';/// staticconstStringIMAGES_AUDIO_PNG='images/audio.png';/// staticconstStringIMAGES_BLUETOOTHOFF_PNG='images/bluetoothoff.png';/// staticconstStringIMAGES_CHILD_PNG='images/child.png';/// staticconstStringIMAGES_COURSE_PNG='images/course.png';}
Since version 1.1.0:
Next command config option also support in config file.
But the command line option has a higher priority than the config file.
watch:false# watch: truepreview:falseoutput:lib/const/r.dart# output: lib/const/resource.dartname:RRR
About
Generate an R file for mapping all assets. Supports preview of image.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.