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.
Add this to your package's pubspec.yaml file:
dependencies: flutter_asset_generator: ^0.2.0
You can install packages from the command line:
$ pub get
$ flutter packages get
Alternatively, your editor might support
pub get or
flutter packages get.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:flutter_asset_generator/builder.dart'; import 'package:flutter_asset_generator/main.dart'; import 'package:flutter_asset_generator/template.dart';
|0.2.0||Aug 12, 2018|
|0.1.2||Aug 6, 2018|
|0.1.1||Aug 6, 2018|
|0.1.0||Aug 6, 2018|
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
We analyzed this package on Apr 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter, web, other
No platform restriction found in primary library
lib/template.dart. (-0.50 points)
lib/template.dart reported 1 hint:
line 41 col 10: The method '_formatDotPartName' isn't used.
The package description is too short. (-20 points)
Add more detail to the
description field of
pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.
Maintain an example. (-10 points)
Create a short demo in the
example/ directory to show how to use this package.
Common filename patterns include
flutter_asset_generator.dart. Packages with multiple examples should provide
For more information see the pub package layout conventions.
|Dart SDK||>=2.0.0-dev.51.0 <3.0.0|