Automatically generate the dart file for pubspec.yaml
The purpose of this library is to help flutter developers automatically generate asset corresponding dart files to 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.
dev_dependencies: build_runner: ^0.9.0 flutter_asset_generator: ^0.1.2
flutter packages pub run build_runner build
cli watch and auto generate:
flutter packages pub run build_runner watch
The command will block, the resource.dart will change when your images change or pubspec.yaml is edited. you can use ctrl+c/cmd+c to exit the program.
Like other build libraries, build/watch commands can now be used normally.
But，user must add a
build.yaml into your project root path. Bacause
build library default only watch
https://www.dartlang.org/tools/pub/package-layout's list. The list have not 'images' path.
build.yaml content is :
targets: $default: sources: - images/** - pubspec.*
the images/** is your image path
and your also download the file from github.
The library will put your every file in the asset path into resource.dart,not just picture files.
However, changes can only be triggered when the files of the following extension are changed.
".png" ".jpg" ".jpeg" ".gif" ".webp" ".bmp" ".wbmp" ".yaml" ".lock"
convert filed name example:
images/1.png => IMAGES_PNG images/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.
If you run the 'flutter packages run build_runner watch' in cli ,then you change the pubspec.yaml, you must stop the watch, becasue flutter's locked.