Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending package information to asset types other than AssetGenImage. #162

Closed
Closed
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -735,7 +735,7 @@ flutter_gen:
# - snake-case
# - dot-delimiter
style: dot-delimiter

fonts:
# Optional
enabled: true
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions packages/core/lib/generators/assets_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ AssetType _constructAssetTree(List<String> assetRelativePathList) {
}

_Statement? _createAssetTypeStatement(
String rootPath,
AssetsGenConfig config,
AssetType assetType,
List<Integration> integrations,
String name,
) {
final childAssetAbsolutePath = join(rootPath, assetType.path);
final childAssetAbsolutePath = join(config.rootPath, assetType.path);
if (assetType.isSupportedImage) {
return _Statement(
type: 'AssetGenImage',
Expand All @@ -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,
);
Expand All @@ -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,
);
Expand Down Expand Up @@ -214,7 +218,7 @@ String _dotDelimiterStyleDefinition(
.mapToIsUniqueWithoutExtension()
.map(
(e) => _createAssetTypeStatement(
config.rootPath,
config,
e.assetType,
integrations,
(e.isUniqueWithoutExtension
Expand Down Expand Up @@ -297,7 +301,7 @@ String _flatStyleDefinition(
.mapToIsUniqueWithoutExtension()
.map(
(e) => _createAssetTypeStatement(
config.rootPath,
config,
e.assetType,
integrations,
createName(e),
Expand Down
6 changes: 5 additions & 1 deletion packages/core/lib/settings/pubspec.g.dart

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

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