spider 0.1.3
spider: ^0.1.3 copied to clipboard
A small dart command-line tool to generate Assets dart code from the assets folder.
Spider #
A small dart library to generate Assets dart code from assets folder. It generates dart class with static const variables in it which can be used to reference the assets safely anywhere in the flutter app.
Note: This package is in very early stages of its alpha release. This is
for demo purpose for now. Avoid using it in production code as most of
the features are more likely to be changed.
Example #
Before
Widget build(BuildContext context) {
return Image(image: AssetImage('assets/background.png'));
}
After
Widget build(BuildContext context) {
return Image(image: AssetImage(Assets.background));
}
Generated Assets Class
class Assets {
static const String background = 'assets/background.png';
}
This method allows no error scope for string typos. Also, it provides auto-complete in the IDE which comes very handy when you have large amount of assets.
Installation #
This is package is an independent library that is not linked to your project. So there's no need to add it to your flutter project as it works as a global command line tool for all of your projects.
pub global activate spider
Run following command to see help:
spider --help
Usage #
Using default configuration #
By default, Spider will look for assets in 'assets' folder and will generate Dart
class with name Assets
in 'lib/res/assets.dart' file.
Default Configs
path: assets
class_name: Assets
package: res
Customize Configuration #
To use custom configurations, Spider searches for a yaml file named 'spider.yaml' or 'spider.yml' in the root directory of the flutter project. see default configs block for information on available configurations.
Create Configuration File
Spider provides a very easy and straight forward way to create a configuration file. Execute following command and it will create a configuration file with default configurations in it.
spider create
Now you can modify available configurations and Spider will use those configs when generating dart code.
see help for more information:
spider create --help
Generate Code #
Run following command to generate dart code:
spider build
Watch Directory #
Spider can also watch given directory for changes in files and rebuild dart code automatically. Use following command to watch for changes:
spider build --watch
see help for more information:
spider build --help
License #
Copyright © 2020 Birju Vachhani
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.