Productivity
Spider is a small Dart library that generates Assets Dart code from an assets folder. It creates a Dart class with static const variables, allowing safe referencing of assets throughout a Flutter app.
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 prevents string typos and provides auto-complete functionality in IDEs, which is useful for managing a large number of assets.
Install using pub:
dart pub global activate spider
Install using Homebrew:
brew tap birjuvachhani/spider
brew install spider
Usage:
Create Configuration File:
spider create
Create Configuration File and append configs to pubspec.yaml:
spider create --add-in-pubspec
Create Configuration File with a custom directory path:
spider create -p ./directory/path/for/config
Generate Dart code:
spider build
Watch for changes and rebuild automatically:
spider build --watch
Enable smart watch:
spider build --smart-watch
Categorize assets by file extension:
path: assets
class_name: Assets
package: res
types: [jpg, png, jpeg, webp, bmp, gif]
Use prefixes for generated dart references:
path: assets
class_name: Assets
package: res
prefix: ic
Advanced Configuration and Grouping:
groups:
path: assets/images
class_name: Images
package: res
path: assets/vectors
class_name: Svgs
package: res
Generate tests for asset references:
generate_tests: true
Generate values list:
use_references_list: true
Enable verbose logging:
spider build --verbose
For more information, check out the Spider GitHub repository.
Spider is licensed under the Apache License, Version 2.0.