From 941dc2d04ff69dde29ef033297e81ee91f5e8bca Mon Sep 17 00:00:00 2001 From: b2nkuu Date: Sat, 17 Aug 2024 14:46:20 +0700 Subject: [PATCH 1/4] feat: add keep config at build.yaml --- README.md | 17 +++++++ packages/command/bin/flutter_gen_command.dart | 14 +++++- packages/core/lib/flutter_generator.dart | 4 +- packages/core/lib/settings/config.dart | 45 ++++++++++++++----- packages/core/test/flutter_gen_test.dart | 22 +++++++++ .../core/test_resources/build_output.yaml | 8 ++++ packages/runner/lib/flutter_gen_runner.dart | 11 ++++- 7 files changed, 106 insertions(+), 15 deletions(-) create mode 100644 packages/core/test_resources/build_output.yaml diff --git a/README.md b/README.md index 17ac5980..bbe41b68 100644 --- a/README.md +++ b/README.md @@ -267,6 +267,23 @@ class $AssetsImagesGen { } ``` +#### Support generate at **build.yaml** +Support generates dart files based on the key **`targets.$default.builders`** and **`flutter_gen.options`** +of [`build.yaml`](https://github.com/dart-lang/build/blob/master/build_config/README.md). + +```yaml +# build.yaml +# ... + +targets: + $default: + builders: + flutter_gen: + options: + output: lib/build_gen/ # Optional (default: lib/gen/) + line_length: 120 # Optional (default: 80) +``` + #### Including additional metadata At build time, additional metadata may be included in the generated class, by using the diff --git a/packages/command/bin/flutter_gen_command.dart b/packages/command/bin/flutter_gen_command.dart index 3ed33f6d..cee70e64 100644 --- a/packages/command/bin/flutter_gen_command.dart +++ b/packages/command/bin/flutter_gen_command.dart @@ -14,6 +14,13 @@ void main(List args) { defaultsTo: 'pubspec.yaml', ); + parser.addOption( + 'build', + abbr: 'b', + help: 'Set the path of build.yaml.', + defaultsTo: 'build.yaml', + ); + parser.addFlag( 'help', abbr: 'h', @@ -45,5 +52,10 @@ void main(List args) { } final pubspecPath = safeCast(results['config']); - FlutterGenerator(File(pubspecPath!).absolute).build(); + final pubspecFile = File(pubspecPath!).absolute; + + final buildPath = safeCast(results['build']); + final buildFile = File(buildPath!).absolute; + + FlutterGenerator(pubspecFile, buildFile: buildFile).build(); } diff --git a/packages/core/lib/flutter_generator.dart b/packages/core/lib/flutter_generator.dart index c683e8af..ec35cd09 100644 --- a/packages/core/lib/flutter_generator.dart +++ b/packages/core/lib/flutter_generator.dart @@ -11,18 +11,20 @@ import 'package:path/path.dart'; class FlutterGenerator { const FlutterGenerator( this.pubspecFile, { + this.buildFile, this.assetsName = 'assets.gen.dart', this.colorsName = 'colors.gen.dart', this.fontsName = 'fonts.gen.dart', }); final File pubspecFile; + final File? buildFile; final String assetsName; final String colorsName; final String fontsName; Future build({Config? config, FileWriter? writer}) async { - config ??= loadPubspecConfigOrNull(pubspecFile); + config ??= loadPubspecConfigOrNull(pubspecFile, buildFile: buildFile); if (config == null) return; final flutter = config.pubspec.flutter; diff --git a/packages/core/lib/settings/config.dart b/packages/core/lib/settings/config.dart index b9018e88..452690e0 100644 --- a/packages/core/lib/settings/config.dart +++ b/packages/core/lib/settings/config.dart @@ -15,23 +15,46 @@ class Config { final File pubspecFile; } -Config loadPubspecConfig(File pubspecFile) { - stdout.writeln('$flutterGenVersion Loading ... ' - '${normalize(join( - basename(pubspecFile.parent.path), - basename(pubspecFile.path), - ))}'); - final content = pubspecFile.readAsStringSync(); - final userMap = loadYaml(content) as Map?; +Config loadPubspecConfig(File pubspecFile, {File? buildFile}) { + final pubspecLocaleHint = normalize( + join(basename(pubspecFile.parent.path), basename(pubspecFile.path)), + ); + final buildLocaleHint = buildFile != null && buildFile.existsSync() + ? ', ${normalize( + join(basename(buildFile.parent.path), basename(buildFile.path)), + )} ' + : ''; + + stdout.writeln( + '$flutterGenVersion Loading ... $pubspecLocaleHint$buildLocaleHint', + ); + final defaultMap = loadYaml(configDefaultYamlContent) as Map?; - final mergedMap = mergeMap([defaultMap, userMap]); + + final pubspecContent = pubspecFile.readAsStringSync(); + final pubspecMap = loadYaml(pubspecContent) as Map?; + + var mergedMap = mergeMap([defaultMap, pubspecMap]); + + if (buildFile != null && buildFile.existsSync()) { + final buildContent = buildFile.readAsStringSync(); + final rawMap = loadYaml(buildContent) as Map?; + final optionBuildMap = rawMap?['targets']?[r'$default']?['builders'] + ?['flutter_gen']?['options']; + + if (optionBuildMap != null) { + final buildMap = {'flutter_gen': optionBuildMap}; + mergedMap = mergeMap([mergedMap, buildMap]); + } + } + final pubspec = Pubspec.fromJson(mergedMap); return Config._(pubspec: pubspec, pubspecFile: pubspecFile); } -Config? loadPubspecConfigOrNull(File pubspecFile) { +Config? loadPubspecConfigOrNull(File pubspecFile, {File? buildFile}) { try { - return loadPubspecConfig(pubspecFile); + return loadPubspecConfig(pubspecFile, buildFile: buildFile); } on FileSystemException catch (e) { stderr.writeln(e.message); } on InvalidSettingsException catch (e) { diff --git a/packages/core/test/flutter_gen_test.dart b/packages/core/test/flutter_gen_test.dart index cdcf03f4..4be77622 100644 --- a/packages/core/test/flutter_gen_test.dart +++ b/packages/core/test/flutter_gen_test.dart @@ -180,5 +180,27 @@ void main() { expect(File('test_resources/lib/gen/$fonts').existsSync(), false); expect(File('test_resources/lib/gen/$colors').existsSync(), false); }); + + test('with build_output.yaml', () async { + const pubspec = 'test_resources/pubspec_normal.yaml'; + const build = 'test_resources/build_output.yaml'; + const assets = 'pubspec_assets.gen.dart'; + const colors = 'pubspec_colors.gen.dart'; + const fonts = 'pubspec_fonts.gen.dart'; + + await FlutterGenerator( + File(pubspec), + buildFile: File(build), + assetsName: assets, + colorsName: colors, + fontsName: fonts, + ).build(); + expect(File('test_resources/lib/build_gen/$assets').readAsStringSync(), + isNotEmpty); + expect(File('test_resources/lib/build_gen/$fonts').readAsStringSync(), + isNotEmpty); + expect(File('test_resources/lib/build_gen/$colors').readAsStringSync(), + isNotEmpty); + }); }); } diff --git a/packages/core/test_resources/build_output.yaml b/packages/core/test_resources/build_output.yaml new file mode 100644 index 00000000..7a458884 --- /dev/null +++ b/packages/core/test_resources/build_output.yaml @@ -0,0 +1,8 @@ +name: test + +targets: + $default: + builders: + flutter_gen: + options: + output: lib/build_gen/ \ No newline at end of file diff --git a/packages/runner/lib/flutter_gen_runner.dart b/packages/runner/lib/flutter_gen_runner.dart index 47c085fd..ace44a0c 100644 --- a/packages/runner/lib/flutter_gen_runner.dart +++ b/packages/runner/lib/flutter_gen_runner.dart @@ -21,8 +21,15 @@ class FlutterGenBuilder extends Builder { ); } - final generator = FlutterGenerator(File('pubspec.yaml')); - late final _config = loadPubspecConfigOrNull(generator.pubspecFile); + final generator = FlutterGenerator( + File('pubspec.yaml'), + buildFile: File('build.yaml'), + ); + + late final _config = loadPubspecConfigOrNull( + generator.pubspecFile, + buildFile: generator.buildFile, + ); _FlutterGenBuilderState? _currentState; @override From b020cac0eee708d67f4988697211d24f88c6da10 Mon Sep 17 00:00:00 2001 From: b2nkuu Date: Wed, 28 Aug 2024 18:33:00 +0700 Subject: [PATCH 2/4] feat: update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index bbe41b68..e2b6f253 100644 --- a/README.md +++ b/README.md @@ -283,6 +283,11 @@ targets: output: lib/build_gen/ # Optional (default: lib/gen/) line_length: 120 # Optional (default: 80) ``` +##### Prority of configure (High -> Low) +``` +build.yaml -> pubspec.yaml -> default_config +``` + #### Including additional metadata From 6f39d2b34683f860182cdd74c491a6d0ae5c7233 Mon Sep 17 00:00:00 2001 From: b2nkuu Date: Thu, 5 Sep 2024 21:50:33 +0700 Subject: [PATCH 3/4] fix: add log reading options from --- README.md | 18 ++++++++++++++++++ packages/core/lib/settings/config.dart | 15 +++++++++------ packages/core/test_resources/build_output.yaml | 13 ++++++++++++- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a7d358c9..15f5c02c 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,24 @@ flutter: style: italic ``` +### build.yaml + +You can also configure generate options in the `build.yaml`, it will be read before the `pubspec.yaml` if it exists. + + +```yaml +# build.yaml +# ... + +targets: + $default: + builders: + flutter_gen: + options: + output: lib/build_gen/ # Optional (default: lib/gen/) + line_length: 120 # Optional (default: 80) +``` + ## Available Parsers ### Assets diff --git a/packages/core/lib/settings/config.dart b/packages/core/lib/settings/config.dart index 452690e0..0ede412c 100644 --- a/packages/core/lib/settings/config.dart +++ b/packages/core/lib/settings/config.dart @@ -20,13 +20,11 @@ Config loadPubspecConfig(File pubspecFile, {File? buildFile}) { join(basename(pubspecFile.parent.path), basename(pubspecFile.path)), ); final buildLocaleHint = buildFile != null && buildFile.existsSync() - ? ', ${normalize( - join(basename(buildFile.parent.path), basename(buildFile.path)), - )} ' + ? join(basename(buildFile.parent.path), basename(buildFile.path)) : ''; stdout.writeln( - '$flutterGenVersion Loading ... $pubspecLocaleHint$buildLocaleHint', + '$flutterGenVersion Loading ...', ); final defaultMap = loadYaml(configDefaultYamlContent) as Map?; @@ -35,16 +33,21 @@ Config loadPubspecConfig(File pubspecFile, {File? buildFile}) { final pubspecMap = loadYaml(pubspecContent) as Map?; var mergedMap = mergeMap([defaultMap, pubspecMap]); + stdout.writeln( + 'Reading FlutterGen options from $pubspecLocaleHint', + ); if (buildFile != null && buildFile.existsSync()) { final buildContent = buildFile.readAsStringSync(); final rawMap = loadYaml(buildContent) as Map?; - final optionBuildMap = rawMap?['targets']?[r'$default']?['builders'] - ?['flutter_gen']?['options']; + final optionBuildMap = rawMap?['targets']?[r'$default']?['builders']?['flutter_gen']?['options']; if (optionBuildMap != null) { final buildMap = {'flutter_gen': optionBuildMap}; mergedMap = mergeMap([mergedMap, buildMap]); + stdout.writeln( + 'Reading FlutterGen options from $buildLocaleHint', + ); } } diff --git a/packages/core/test_resources/build_output.yaml b/packages/core/test_resources/build_output.yaml index 7a458884..649fdc92 100644 --- a/packages/core/test_resources/build_output.yaml +++ b/packages/core/test_resources/build_output.yaml @@ -5,4 +5,15 @@ targets: builders: flutter_gen: options: - output: lib/build_gen/ \ No newline at end of file + output: lib/build_gen/ + line_length: 80 + + integrations: + flutter_svg: true + flare_flutter: true + rive: true + lottie: true + + colors: + inputs: + - assets/color/colors.xml \ No newline at end of file From c2f70f252c8b9f21ce00889455142f6dbdfb461c Mon Sep 17 00:00:00 2001 From: b2nkuu Date: Sat, 7 Sep 2024 00:09:42 +0700 Subject: [PATCH 4/4] fix: revise README.md and add actual_data test --- README.md | 22 - packages/core/test/assets_gen_test.dart | 9 + packages/core/test/flutter_gen_test.dart | 8 +- packages/core/test/gen_test_helper.dart | 23 +- .../actual_data/build_assets.gen.dart | 439 ++++++++++++++++++ .../core/test_resources/build_assets.yaml | 9 + .../core/test_resources/build_output.yaml | 19 - 7 files changed, 476 insertions(+), 53 deletions(-) create mode 100644 packages/core/test_resources/actual_data/build_assets.gen.dart create mode 100644 packages/core/test_resources/build_assets.yaml delete mode 100644 packages/core/test_resources/build_output.yaml diff --git a/README.md b/README.md index 15f5c02c..771014cf 100644 --- a/README.md +++ b/README.md @@ -314,28 +314,6 @@ class $AssetsImagesGen { } ``` -#### Support generate at **build.yaml** -Support generates dart files based on the key **`targets.$default.builders`** and **`flutter_gen.options`** -of [`build.yaml`](https://github.com/dart-lang/build/blob/master/build_config/README.md). - -```yaml -# build.yaml -# ... - -targets: - $default: - builders: - flutter_gen: - options: - output: lib/build_gen/ # Optional (default: lib/gen/) - line_length: 120 # Optional (default: 80) -``` -##### Prority of configure (High -> Low) -``` -build.yaml -> pubspec.yaml -> default_config -``` - - #### Including additional metadata At build time, additional metadata may be included in the generated class, by using the diff --git a/packages/core/test/assets_gen_test.dart b/packages/core/test/assets_gen_test.dart index 32519cc4..ac1181a1 100644 --- a/packages/core/test/assets_gen_test.dart +++ b/packages/core/test/assets_gen_test.dart @@ -213,6 +213,15 @@ void main() { final names = got.map((e) => e.name); expect(names.sorted(), tests.values.sorted()); }); + + test('Assets on pubspec_assets.yaml and override with build_assets.yaml ', () async { + const pubspec = 'test_resources/pubspec_assets.yaml'; + const build = 'test_resources/build_assets.yaml'; + const fact = 'test_resources/actual_data/build_assets.gen.dart'; + const generated = 'test_resources/lib/build_gen/assets.gen.dart'; + + await expectedAssetsGen(pubspec, generated, fact, build: build); + }); }); group('Test generatePackageNameForConfig', () { diff --git a/packages/core/test/flutter_gen_test.dart b/packages/core/test/flutter_gen_test.dart index ab22997a..4b269d96 100644 --- a/packages/core/test/flutter_gen_test.dart +++ b/packages/core/test/flutter_gen_test.dart @@ -180,12 +180,12 @@ void main() { expect(File('test_resources/lib/gen/$colors').existsSync(), false); }); - test('with build_output.yaml', () async { + test('With build_output.yaml', () async { const pubspec = 'test_resources/pubspec_normal.yaml'; const build = 'test_resources/build_output.yaml'; - const assets = 'pubspec_assets.gen.dart'; - const colors = 'pubspec_colors.gen.dart'; - const fonts = 'pubspec_fonts.gen.dart'; + const assets = 'build_assets.gen.dart'; + const colors = 'build_colors.gen.dart'; + const fonts = 'build_fonts.gen.dart'; await FlutterGenerator( File(pubspec), diff --git a/packages/core/test/gen_test_helper.dart b/packages/core/test/gen_test_helper.dart index 104dd8af..cf7c5145 100644 --- a/packages/core/test/gen_test_helper.dart +++ b/packages/core/test/gen_test_helper.dart @@ -14,15 +14,21 @@ Future clearTestResults() async {} Future> runAssetsGen( String pubspec, String generated, - String fact, -) async { + String fact, { + String? build, +}) async { + final pubspecFile = File(pubspec); + + File? buildFile; + if (build != null) buildFile = File(build); + await FlutterGenerator( - File(pubspec), + pubspecFile, + buildFile: buildFile, assetsName: p.basename(generated), ).build(); - final pubspecFile = File(pubspec); - final config = loadPubspecConfig(pubspecFile); + final config = loadPubspecConfig(pubspecFile, buildFile: buildFile); final formatter = DartFormatter( pageWidth: config.pubspec.flutterGen.lineLength, lineEnding: '\n', @@ -42,9 +48,10 @@ Future> runAssetsGen( Future expectedAssetsGen( String pubspec, String generated, - String fact, -) async { - final results = await runAssetsGen(pubspec, generated, fact); + String fact, { + String? build, +}) async { + final results = await runAssetsGen(pubspec, generated, fact, build: build); final actual = results.first, expected = results.last; expect( File(generated).readAsStringSync(), diff --git a/packages/core/test_resources/actual_data/build_assets.gen.dart b/packages/core/test_resources/actual_data/build_assets.gen.dart new file mode 100644 index 00000000..c660a51e --- /dev/null +++ b/packages/core/test_resources/actual_data/build_assets.gen.dart @@ -0,0 +1,439 @@ +/// GENERATED CODE - DO NOT MODIFY BY HAND +/// ***************************************************** +/// FlutterGen +/// ***************************************************** + +// coverage:ignore-file +// ignore_for_file: type=lint +// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use + +import 'package:flare_flutter/flare_actor.dart' + as _flare_actor; +import 'package:flare_flutter/flare_controller.dart' + as _flare_controller; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_svg/flutter_svg.dart' + as _svg; +import 'package:vector_graphics/vector_graphics.dart' + as _vg; + +class $PicturesGen { + const $PicturesGen(); + + /// File path: pictures/chip5.jpg + AssetGenImage get chip5 => + const AssetGenImage( + 'pictures/chip5.jpg'); + + /// List of all assets + List get values => + [chip5]; +} + +class $AssetsFlareGen { + const $AssetsFlareGen(); + + /// File path: assets/flare/Penguin.flr + FlareGenImage get penguin => + const FlareGenImage( + 'assets/flare/Penguin.flr'); + + /// List of all assets + List get values => + [penguin]; +} + +class $AssetsImagesGen { + const $AssetsImagesGen(); + + /// File path: assets/images/chip1.jpg + AssetGenImage get chip1 => + const AssetGenImage( + 'assets/images/chip1.jpg'); + + /// File path: assets/images/chip2.jpg + AssetGenImage get chip2 => + const AssetGenImage( + 'assets/images/chip2.jpg'); + + /// Directory path: assets/images/chip3 + $AssetsImagesChip3Gen get chip3 => + const $AssetsImagesChip3Gen(); + + /// Directory path: assets/images/chip4 + $AssetsImagesChip4Gen get chip4 => + const $AssetsImagesChip4Gen(); + + /// Directory path: assets/images/icons + $AssetsImagesIconsGen get icons => + const $AssetsImagesIconsGen(); + + /// File path: assets/images/logo.png + AssetGenImage get logo => + const AssetGenImage( + 'assets/images/logo.png'); + + /// File path: assets/images/profile.jpg + AssetGenImage get profileJpg => + const AssetGenImage( + 'assets/images/profile.jpg'); + + /// File path: assets/images/profile.png + AssetGenImage get profilePng => + const AssetGenImage( + 'assets/images/profile.png'); + + /// List of all assets + List get values => [ + chip1, + chip2, + logo, + profileJpg, + profilePng + ]; +} + +class $AssetsJsonGen { + const $AssetsJsonGen(); + + /// File path: assets/json/list.json + String get list => + 'assets/json/list.json'; + + /// File path: assets/json/map.json + String get map => + 'assets/json/map.json'; + + /// List of all assets + List get values => + [list, map]; +} + +class $AssetsMovieGen { + const $AssetsMovieGen(); + + /// File path: assets/movie/the_earth.mp4 + String get theEarth => + 'assets/movie/the_earth.mp4'; + + /// List of all assets + List get values => [theEarth]; +} + +class $AssetsUnknownGen { + const $AssetsUnknownGen(); + + /// File path: assets/unknown/unknown_mime_type.bk + String get unknownMimeType => + 'assets/unknown/unknown_mime_type.bk'; + + /// List of all assets + List get values => + [unknownMimeType]; +} + +class $AssetsImagesChip3Gen { + const $AssetsImagesChip3Gen(); + + /// File path: assets/images/chip3/chip3.jpg + AssetGenImage get chip3 => + const AssetGenImage( + 'assets/images/chip3/chip3.jpg'); + + /// List of all assets + List get values => + [chip3]; +} + +class $AssetsImagesChip4Gen { + const $AssetsImagesChip4Gen(); + + /// File path: assets/images/chip4/chip4.jpg + AssetGenImage get chip4 => + const AssetGenImage( + 'assets/images/chip4/chip4.jpg'); + + /// List of all assets + List get values => + [chip4]; +} + +class $AssetsImagesIconsGen { + const $AssetsImagesIconsGen(); + + /// File path: assets/images/icons/dart@test.svg + SvgGenImage get dartTest => + const SvgGenImage( + 'assets/images/icons/dart@test.svg'); + + /// File path: assets/images/icons/fuchsia.svg + SvgGenImage get fuchsia => + const SvgGenImage( + 'assets/images/icons/fuchsia.svg'); + + /// File path: assets/images/icons/kmm.svg + SvgGenImage get kmm => + const SvgGenImage( + 'assets/images/icons/kmm.svg'); + + /// File path: assets/images/icons/paint.svg + SvgGenImage get paint => + const SvgGenImage( + 'assets/images/icons/paint.svg'); + + /// List of all assets + List get values => + [dartTest, fuchsia, kmm, paint]; +} + +class Assets { + Assets._(); + + static const String changelog = + 'CHANGELOG.md'; + static const $AssetsFlareGen flare = + $AssetsFlareGen(); + static const $AssetsImagesGen images = + $AssetsImagesGen(); + static const $AssetsJsonGen json = + $AssetsJsonGen(); + static const $AssetsMovieGen movie = + $AssetsMovieGen(); + static const $AssetsUnknownGen + unknown = $AssetsUnknownGen(); + static const $PicturesGen pictures = + $PicturesGen(); + + /// List of all assets + static List get values => + [changelog]; +} + +class AssetGenImage { + const AssetGenImage( + this._assetName, { + this.size, + this.flavors = const {}, + }); + + final String _assetName; + + final Size? size; + final Set flavors; + + Image image({ + Key? key, + AssetBundle? bundle, + ImageFrameBuilder? frameBuilder, + ImageErrorWidgetBuilder? + errorBuilder, + String? semanticLabel, + bool excludeFromSemantics = false, + double? scale, + double? width, + double? height, + Color? color, + Animation? opacity, + BlendMode? colorBlendMode, + BoxFit? fit, + AlignmentGeometry alignment = + Alignment.center, + ImageRepeat repeat = + ImageRepeat.noRepeat, + Rect? centerSlice, + bool matchTextDirection = false, + bool gaplessPlayback = false, + bool isAntiAlias = false, + String? package, + FilterQuality filterQuality = + FilterQuality.low, + int? cacheWidth, + int? cacheHeight, + }) { + return Image.asset( + _assetName, + key: key, + bundle: bundle, + frameBuilder: frameBuilder, + errorBuilder: errorBuilder, + semanticLabel: semanticLabel, + excludeFromSemantics: + excludeFromSemantics, + scale: scale, + width: width, + height: height, + color: color, + opacity: opacity, + colorBlendMode: colorBlendMode, + fit: fit, + alignment: alignment, + repeat: repeat, + centerSlice: centerSlice, + matchTextDirection: + matchTextDirection, + gaplessPlayback: gaplessPlayback, + isAntiAlias: isAntiAlias, + package: package, + filterQuality: filterQuality, + cacheWidth: cacheWidth, + cacheHeight: cacheHeight, + ); + } + + ImageProvider provider({ + AssetBundle? bundle, + String? package, + }) { + return AssetImage( + _assetName, + bundle: bundle, + package: package, + ); + } + + String get path => _assetName; + + String get keyName => _assetName; +} + +class SvgGenImage { + const SvgGenImage( + this._assetName, { + this.size, + this.flavors = const {}, + }) : _isVecFormat = false; + + const SvgGenImage.vec( + this._assetName, { + this.size, + this.flavors = const {}, + }) : _isVecFormat = true; + + final String _assetName; + final Size? size; + final Set flavors; + final bool _isVecFormat; + + _svg.SvgPicture svg({ + Key? key, + bool matchTextDirection = false, + AssetBundle? bundle, + String? package, + double? width, + double? height, + BoxFit fit = BoxFit.contain, + AlignmentGeometry alignment = + Alignment.center, + bool allowDrawingOutsideViewBox = + false, + WidgetBuilder? placeholderBuilder, + String? semanticsLabel, + bool excludeFromSemantics = false, + _svg.SvgTheme? theme, + ColorFilter? colorFilter, + Clip clipBehavior = Clip.hardEdge, + @deprecated Color? color, + @deprecated + BlendMode colorBlendMode = + BlendMode.srcIn, + @deprecated + bool cacheColorFilter = false, + }) { + final _svg.BytesLoader loader; + if (_isVecFormat) { + loader = _vg.AssetBytesLoader( + _assetName, + assetBundle: bundle, + packageName: package, + ); + } else { + loader = _svg.SvgAssetLoader( + _assetName, + assetBundle: bundle, + packageName: package, + theme: theme, + ); + } + return _svg.SvgPicture( + loader, + key: key, + matchTextDirection: + matchTextDirection, + width: width, + height: height, + fit: fit, + alignment: alignment, + allowDrawingOutsideViewBox: + allowDrawingOutsideViewBox, + placeholderBuilder: + placeholderBuilder, + semanticsLabel: semanticsLabel, + excludeFromSemantics: + excludeFromSemantics, + colorFilter: colorFilter ?? + (color == null + ? null + : ColorFilter.mode(color, + colorBlendMode)), + clipBehavior: clipBehavior, + cacheColorFilter: + cacheColorFilter, + ); + } + + String get path => _assetName; + + String get keyName => _assetName; +} + +class FlareGenImage { + const FlareGenImage( + this._assetName, { + this.flavors = const {}, + }); + + final String _assetName; + final Set flavors; + + _flare_actor.FlareActor flare({ + String? boundsNode, + String? animation, + BoxFit fit = BoxFit.contain, + Alignment alignment = + Alignment.center, + bool isPaused = false, + bool snapToEnd = false, + _flare_controller.FlareController? + controller, + _flare_actor.FlareCompletedCallback? + callback, + Color? color, + bool shouldClip = true, + bool sizeFromArtboard = false, + String? artboard, + bool antialias = true, + }) { + return _flare_actor.FlareActor( + _assetName, + boundsNode: boundsNode, + animation: animation, + fit: fit, + alignment: alignment, + isPaused: isPaused, + snapToEnd: snapToEnd, + controller: controller, + callback: callback, + color: color, + shouldClip: shouldClip, + sizeFromArtboard: + sizeFromArtboard, + artboard: artboard, + antialias: antialias, + ); + } + + String get path => _assetName; + + String get keyName => _assetName; +} diff --git a/packages/core/test_resources/build_assets.yaml b/packages/core/test_resources/build_assets.yaml new file mode 100644 index 00000000..ccd360fd --- /dev/null +++ b/packages/core/test_resources/build_assets.yaml @@ -0,0 +1,9 @@ +name: test + +targets: + $default: + builders: + flutter_gen: + options: + output: lib/build_gen/ + line_length: 120 diff --git a/packages/core/test_resources/build_output.yaml b/packages/core/test_resources/build_output.yaml deleted file mode 100644 index 649fdc92..00000000 --- a/packages/core/test_resources/build_output.yaml +++ /dev/null @@ -1,19 +0,0 @@ -name: test - -targets: - $default: - builders: - flutter_gen: - options: - output: lib/build_gen/ - line_length: 80 - - integrations: - flutter_svg: true - flare_flutter: true - rive: true - lottie: true - - colors: - inputs: - - assets/color/colors.xml \ No newline at end of file