diff --git a/README.md b/README.md index 2131ed63..fd5a5a3f 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ $ fluttergen -c example/pubspec.yaml ## Configuration file [FlutterGen] generates dart files based on the key **`flutter`** and **`flutter_gen`** of [`pubspec.yaml`](https://dart.dev/tools/pub/pubspec). -Default configuration can be found [here](#default-configuration). +Default configuration can be found [here](#default-configuration). ```yaml # pubspec.yaml @@ -739,7 +739,7 @@ flutter_gen: # - snake-case # - dot-delimiter style: dot-delimiter - + fonts: # Optional enabled: true diff --git a/example/pubspec.yaml b/example/pubspec.yaml index befcadae..35bbe1c3 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -32,7 +32,7 @@ dev_dependencies: flutter_gen: output: lib/gen/ # Optional (default: lib/gen/) - line_length: 80 # Optional (default: 80) + line_length: 80 # Optional (default: 80) integrations: flutter_svg: true diff --git a/packages/core/lib/generators/assets_generator.dart b/packages/core/lib/generators/assets_generator.dart index ae9d4ef3..1c8868d7 100644 --- a/packages/core/lib/generators/assets_generator.dart +++ b/packages/core/lib/generators/assets_generator.dart @@ -140,12 +140,12 @@ AssetType _constructAssetTree(List assetRelativePathList) { } _Statement? _createAssetTypeStatement( - String rootPath, + AssetsGenConfig config, AssetType assetType, List integrations, String name, ) { - final childAssetAbsolutePath = join(rootPath, assetType.path); + final childAssetAbsolutePath = join(config.rootPath, assetType.path); if (assetType.isSupportedImage) { return _Statement( type: 'AssetGenImage', @@ -169,12 +169,15 @@ _Statement? _createAssetTypeStatement( final integration = integrations.firstWhereOrNull( (element) => element.isSupport(assetType), ); + final packagePrefix = config.packageParameterLiteral.isNotEmpty + ? 'packages/${config.packageParameterLiteral}/' + : ''; if (integration == null) { return _Statement( type: 'String', filePath: assetType.path, name: name, - value: '\'${posixStyle(assetType.path)}\'', + value: '\'${posixStyle('$packagePrefix${assetType.path}')}\'', isConstConstructor: false, needDartDoc: true, ); @@ -184,7 +187,8 @@ _Statement? _createAssetTypeStatement( type: integration.className, filePath: assetType.path, name: name, - value: integration.classInstantiate(posixStyle(assetType.path)), + value: integration + .classInstantiate(posixStyle('$packagePrefix${assetType.path}')), isConstConstructor: integration.isConstConstructor, needDartDoc: true, ); @@ -214,7 +218,7 @@ String _dotDelimiterStyleDefinition( .mapToIsUniqueWithoutExtension() .map( (e) => _createAssetTypeStatement( - config.rootPath, + config, e.assetType, integrations, (e.isUniqueWithoutExtension @@ -297,7 +301,7 @@ String _flatStyleDefinition( .mapToIsUniqueWithoutExtension() .map( (e) => _createAssetTypeStatement( - config.rootPath, + config, e.assetType, integrations, createName(e), diff --git a/packages/core/lib/settings/pubspec.g.dart b/packages/core/lib/settings/pubspec.g.dart index ea42e5f8..e423cce0 100644 --- a/packages/core/lib/settings/pubspec.g.dart +++ b/packages/core/lib/settings/pubspec.g.dart @@ -117,7 +117,11 @@ FlutterGenAssets _$FlutterGenAssetsFromJson(Map json) => $checkedCreate( ($checkedConvert) { $checkKeys( json, - requiredKeys: const ['enabled', 'package_parameter_enabled', 'style'], + requiredKeys: const [ + 'enabled', + 'package_parameter_enabled', + 'style' + ], ); final val = FlutterGenAssets( enabled: $checkedConvert('enabled', (v) => v as bool), diff --git a/packages/core/test_resources/actual_data/assets_package_parameter.gen.dart b/packages/core/test_resources/actual_data/assets_package_parameter.gen.dart index 79d6cbdb..ac812162 100644 --- a/packages/core/test_resources/actual_data/assets_package_parameter.gen.dart +++ b/packages/core/test_resources/actual_data/assets_package_parameter.gen.dart @@ -29,11 +29,11 @@ class $AssetsImagesIconsGen { /// File path: assets/images/icons/dart@test.svg SvgGenImage get dartTest => - const SvgGenImage('assets/images/icons/dart@test.svg'); + const SvgGenImage('packages/test/assets/images/icons/dart@test.svg'); /// File path: assets/images/icons/fuchsia.svg SvgGenImage get fuchsia => - const SvgGenImage('assets/images/icons/fuchsia.svg'); + const SvgGenImage('packages/test/assets/images/icons/fuchsia.svg'); } class Assets {