Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion examples/example/lib/gen/assets.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class $AssetsLottieWrongGen {
class MyAssets {
MyAssets._();

static const String readme = 'README.md';
static const $AssetsFlareGen flare = $AssetsFlareGen();
static const $AssetsImagesGen images = $AssetsImagesGen();
static const $AssetsJsonGen json = $AssetsJsonGen();
Expand All @@ -190,6 +191,9 @@ class MyAssets {
static const $AssetsMovieGen movie = $AssetsMovieGen();
static const $AssetsRiveGen rive = $AssetsRiveGen();
static const $AssetsUnknownGen unknown = $AssetsUnknownGen();

/// List of all assets
static List<String> get values => [readme];
}

class AssetGenImage {
Expand Down Expand Up @@ -269,10 +273,12 @@ class AssetGenImage {
}

class SvgGenImage {
const SvgGenImage(this._assetName);
const SvgGenImage(this._assetName, {this.size = null});

final String _assetName;

final Size? size;

SvgPicture svg({
Key? key,
bool matchTextDirection = false,
Expand Down
1 change: 1 addition & 0 deletions examples/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ flutter_gen:
flutter:
uses-material-design: true
assets:
- README.md
- assets/images/
- assets/images/chip3/chip3.jpg
- assets/images/chip3/chip3.jpg # duplicated
Expand Down
28 changes: 24 additions & 4 deletions packages/core/lib/generators/assets_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,23 +304,33 @@ String _dotDelimiterStyleDefinition(
AssetsGenConfig config,
List<Integration> integrations,
) {
final rootPath = Directory(config.rootPath).absolute.uri.toFilePath();
final buffer = StringBuffer();
final className = config.flutterGen.assets.outputs.className;
final assetRelativePathList = _getAssetRelativePathList(
config.rootPath,
rootPath,
config.assets,
config.exclude,
);
final assetsStaticStatements = <_Statement>[];

final assetTypeQueue = ListQueue<AssetType>.from(
_constructAssetTree(assetRelativePathList, config.rootPath).children);
_constructAssetTree(assetRelativePathList, rootPath).children);

while (assetTypeQueue.isNotEmpty) {
final assetType = assetTypeQueue.removeFirst();
final assetAbsolutePath = join(config.rootPath, assetType.path);
String assetPath = join(rootPath, assetType.path);
final isDirectory = FileSystemEntity.isDirectorySync(assetPath);
if (isDirectory) {
assetPath = Directory(assetPath).absolute.uri.toFilePath();
} else {
assetPath = File(assetPath).absolute.uri.toFilePath();
}

if (FileSystemEntity.isDirectorySync(assetAbsolutePath)) {
final isRootAsset = !isDirectory &&
File(assetPath).parent.absolute.uri.toFilePath() == rootPath;
// Handles directories, and explicitly handles root path assets.
if (isDirectory || isRootAsset) {
final statements = assetType.children
.mapToIsUniqueWithoutExtension()
.map(
Expand All @@ -339,6 +349,16 @@ String _dotDelimiterStyleDefinition(

if (assetType.isDefaultAssetsDirectory) {
assetsStaticStatements.addAll(statements);
} else if (!isDirectory && isRootAsset) {
// Creates explicit statement.
assetsStaticStatements.add(
_createAssetTypeStatement(
config,
assetType,
integrations,
basenameWithoutExtension(assetType.path).camelCase(),
)!,
);
} else {
final className = '\$${assetType.path.camelCase().capitalize()}Gen';
buffer.writeln(_directoryClassGenDefinition(className, statements));
Expand Down
1 change: 1 addition & 0 deletions packages/core/test_resources/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is the CHANGELOG.md
4 changes: 4 additions & 0 deletions packages/core/test_resources/actual_data/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/core/test_resources/pubspec_assets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ flutter:
- assets/flare/
- assets/movie/
- assets/unknown/unknown_mime_type.bk
- CHANGELOG.md