assetify library
Assetify - Type-safe asset constants generator for Flutter projects.
This library provides tools to automatically generate Dart constants from your Flutter project's assets, eliminating runtime errors from typos and enabling IDE autocomplete for asset paths.
Quick Start
// CLI usage
dart run assetify:generate
dart run assetify:watch
// Programmatic usage
import 'package:assetify/assetify.dart';
final generator = AssetGenerator(
project: project,
outputFile: File('lib/assets.g.dart'),
className: 'Assets',
generateWidgets: true,
logger: Logger(),
);
await generator.generate();
Generated Output
class Assets {
static const String imagesCat = 'assets/images/cat.png';
static const Images images = Images._();
}
extension AssetImageX on String {
Image asImage() => Image.asset(this);
}
Classes
- AssetEntry
- Represents a single asset file with its metadata.
- AssetGenerator
- Generates type-safe Dart constants for Flutter project assets.
- FontFamily
-
Represents a font family declaration from
pubspec.yaml. - ProjectInfo
- Contains project configuration and metadata for asset generation.
- PubspecReader
-
Reads and parses Flutter project configuration from
pubspec.yaml.
Enums
- AssetType
- The type of asset based on file extension and location.
Functions
-
detectAssetType(
String path) → AssetType - Detects the asset type based on file extension and path.
-
fileNameToCamelIdentifier(
String fileName) → String -
fileNameToCamelIdentifierWithExt(
String fileName) → String - Converts a filename to a camelCase identifier, including the file extension as a suffix.
-
filePathToCamelIdentifier(
String filePath) → String -
filePathToCamelIdentifierWithExt(
String filePath) → String - Converts a file path to a camelCase identifier, including the file extension as a suffix.
-
normalizedAssetPath(
String path) → String - Normalizes an asset path to use forward slashes and relative format.
-
toCamelIdentifier(
String input) → String - Converts input string to a valid camelCase Dart identifier.
-
toPascalIdentifier(
String input) → String - Converts input string to a valid PascalCase Dart identifier.