Skip to content

Commit

Permalink
Changed the SvgIntegration to parse metadata, and include the image's…
Browse files Browse the repository at this point in the history
… width/height in the generated assets.gen.dart.
  • Loading branch information
bramp committed Oct 19, 2023
1 parent a1ea601 commit 4abf8a0
Show file tree
Hide file tree
Showing 9 changed files with 382 additions and 5 deletions.
12 changes: 10 additions & 2 deletions packages/core/lib/generators/integrations/svg_integration.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import 'dart:io';

import 'package:flutter_gen_core/generators/integrations/integration.dart';
import 'package:flutter_gen_core/settings/asset_type.dart';
import 'package:vector_graphics_compiler/vector_graphics_compiler.dart';

class SvgIntegration extends Integration {
SvgIntegration(String packageParameterLiteral)
SvgIntegration(String packageParameterLiteral, {this.parseMetadata = false})
: super(packageParameterLiteral);

String get packageExpression => isPackage ? ' = package' : '';

final bool parseMetadata;

@override
List<String> get requiredImports => [
'package:flutter_svg/flutter_svg.dart',
Expand All @@ -17,11 +22,14 @@ class SvgIntegration extends Integration {
String get classOutput => _classDefinition;

String get _classDefinition => '''class SvgGenImage {
const SvgGenImage(this._assetName);
const SvgGenImage(this._assetName, {this.size = null});
final String _assetName;
${isPackage ? "\n static const String package = '$packageParameterLiteral';" : ''}
final Size? size;
SvgPicture svg({
Key? key,
bool matchTextDirection = false,
Expand Down
1 change: 1 addition & 0 deletions packages/core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies:
dart_style: ^2.2.4
args: ^2.0.0
pub_semver: ^2.0.0
vector_graphics_compiler: ^1.1.9

dev_dependencies:
lints: ^2.0.0
Expand Down
8 changes: 8 additions & 0 deletions packages/core/test/assets_gen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ void main() {

await expectedAssetsGen(pubspec, generated, fact);
});

test('Assets with parse metadata enabled', () async {
const pubspec = 'test_resources/pubspec_assets_parse_metadata.yaml';
const fact = 'test_resources/actual_data/assets_parse_metadata.gen.dart';
const generated = 'test_resources/lib/gen/assets_parse_metadata.gen.dart';

await expectedAssetsGen(pubspec, generated, fact);
});
});

group('Test generatePackageNameForConfig', () {
Expand Down
3 changes: 2 additions & 1 deletion 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.

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

Loading

0 comments on commit 4abf8a0

Please sign in to comment.