diff --git a/README.md b/README.md index 5c3e01d74..e3714a8e8 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,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](https://github.com/FlutterGen/flutter_gen/tree/main/packages/core/lib/settings/config_default.dart). +Default configuration can be found [here](https://github.com/FlutterGen/flutter_gen/tree/main/packages/core/lib/settings/config_default.dart). ```yaml # pubspec.yaml @@ -173,7 +173,6 @@ flutter: You can also configure generate options in the `build.yaml`, it will be read before the `pubspec.yaml` if it exists. - ```yaml # build.yaml # ... @@ -276,7 +275,9 @@ Widget build(BuildContext context) { ); } ``` + or + ```dart // Explicit usage for `Image`/`SvgPicture`/`Lottie`. Widget build(BuildContext context) { @@ -340,6 +341,32 @@ Widget build(BuildContext context) { } ``` +You can use `parse_animation` to generate more animation details. +It will automatically parse all animation information for GIF and WebP files, +including frames, duration, etc. As this option significantly increases generation time, +The option is disabled by default; enabling it will significantly increase the generation elapse. + +```yaml +flutter_gen: + images: + parse_animation: true # <- Add this line (default: false) + # This option implies parse_metadata: true when parsing images. +``` + +For GIF and WebP animation, several new nullable field is added to the +generated class. For example: + +```dart +AssetGenImage get animated => + const AssetGenImage( + 'assets/images/animated.webp', + size: Size(209.0, 49.0), + isAnimation: true, + duration: Duration(milliseconds: 1000), + frames: 15, + ); +``` + #### Usage Example [FlutterGen] generates [Image](https://api.flutter.dev/flutter/widgets/Image-class.html) class if the asset is Flutter supported image format. @@ -575,7 +602,9 @@ Plugin issues that are not specific to [FlutterGen] can be filed in the [Flutter ### Known Issues #### Bad State: No Element when using build_runner + If you get an error message like this: + ``` [SEVERE] flutter_gen_runner:flutter_gen_runner on $package$: @@ -614,8 +643,6 @@ output-localization-file: app_localizations.dart synthetic-package: false <--- ⚠️Add this line⚠️ ``` -If you get - ## Contributing **We are looking for co-developers.** diff --git a/examples/example/lib/gen/assets.gen.dart b/examples/example/lib/gen/assets.gen.dart index d768c99ee..60f0aaedb 100644 --- a/examples/example/lib/gen/assets.gen.dart +++ b/examples/example/lib/gen/assets.gen.dart @@ -54,8 +54,13 @@ class $AssetsImagesGen { const AssetGenImage('assets/images/profile.png'); /// List of all assets - List get values => - [chip1, chip2, logo, profileJpg, profilePng]; + List get values => [ + chip1, + chip2, + logo, + profileJpg, + profilePng, + ]; } class $AssetsJsonGen { @@ -102,13 +107,13 @@ class $AssetsLottieGen { /// List of all assets List get values => [ - xuiIZ9X1Rf, - alarmClockLottieV440, - cat, - geometricalAnimation, - hamburgerArrow, - spinningCarrousel - ]; + xuiIZ9X1Rf, + alarmClockLottieV440, + cat, + geometricalAnimation, + hamburgerArrow, + spinningCarrousel, + ]; } class $AssetsMixGen { @@ -175,10 +180,8 @@ class $AssetsImagesChip4Gen { const $AssetsImagesChip4Gen(); /// File path: assets/images/chip4/chip4.jpg - AssetGenImage get chip4 => const AssetGenImage( - 'assets/images/chip4/chip4.jpg', - flavors: {'extern'}, - ); + AssetGenImage get chip4 => + const AssetGenImage('assets/images/chip4/chip4.jpg', flavors: {'extern'}); /// List of all assets List get values => [chip4]; @@ -236,11 +239,7 @@ class MyAssets { } class AssetGenImage { - const AssetGenImage( - this._assetName, { - this.size, - this.flavors = const {}, - }); + const AssetGenImage(this._assetName, {this.size, this.flavors = const {}}); final String _assetName; @@ -300,15 +299,8 @@ class AssetGenImage { ); } - ImageProvider provider({ - AssetBundle? bundle, - String? package, - }) { - return AssetImage( - _assetName, - bundle: bundle, - package: package, - ); + ImageProvider provider({AssetBundle? bundle, String? package}) { + return AssetImage(_assetName, bundle: bundle, package: package); } String get path => _assetName; @@ -317,17 +309,11 @@ class AssetGenImage { } 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; + 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; @@ -381,7 +367,8 @@ class SvgGenImage { placeholderBuilder: placeholderBuilder, semanticsLabel: semanticsLabel, excludeFromSemantics: excludeFromSemantics, - colorFilter: colorFilter ?? + colorFilter: + colorFilter ?? (color == null ? null : ColorFilter.mode(color, colorBlendMode)), clipBehavior: clipBehavior, cacheColorFilter: cacheColorFilter, @@ -394,10 +381,7 @@ class SvgGenImage { } class RiveGenImage { - const RiveGenImage( - this._assetName, { - this.flavors = const {}, - }); + const RiveGenImage(this._assetName, {this.flavors = const {}}); final String _assetName; final Set flavors; @@ -435,10 +419,7 @@ class RiveGenImage { } class LottieGenImage { - const LottieGenImage( - this._assetName, { - this.flavors = const {}, - }); + const LottieGenImage(this._assetName, {this.flavors = const {}}); final String _assetName; final Set flavors; @@ -455,11 +436,8 @@ class LottieGenImage { _lottie.LottieImageProviderFactory? imageProviderFactory, Key? key, AssetBundle? bundle, - Widget Function( - BuildContext, - Widget, - _lottie.LottieComposition?, - )? frameBuilder, + Widget Function(BuildContext, Widget, _lottie.LottieComposition?)? + frameBuilder, ImageErrorWidgetBuilder? errorBuilder, double? width, double? height, diff --git a/examples/example/lib/gen/colors.gen.dart b/examples/example/lib/gen/colors.gen.dart index 8d4254e62..c85046141 100644 --- a/examples/example/lib/gen/colors.gen.dart +++ b/examples/example/lib/gen/colors.gen.dart @@ -39,21 +39,19 @@ class MyColorName { /// 700: #FFC31F1F /// 800: #FFBD1919 /// 900: #FFB20F0F - static const MaterialColor crimsonRed = MaterialColor( - 0xFFCF2A2A, - { - 50: Color(0xFFF9E5E5), - 100: Color(0xFFF1BFBF), - 200: Color(0xFFE79595), - 300: Color(0xFFDD6A6A), - 400: Color(0xFFD64A4A), - 500: Color(0xFFCF2A2A), - 600: Color(0xFFCA2525), - 700: Color(0xFFC31F1F), - 800: Color(0xFFBD1919), - 900: Color(0xFFB20F0F), - }, - ); + static const MaterialColor crimsonRed = + MaterialColor(0xFFCF2A2A, { + 50: Color(0xFFF9E5E5), + 100: Color(0xFFF1BFBF), + 200: Color(0xFFE79595), + 300: Color(0xFFDD6A6A), + 400: Color(0xFFD64A4A), + 500: Color(0xFFCF2A2A), + 600: Color(0xFFCA2525), + 700: Color(0xFFC31F1F), + 800: Color(0xFFBD1919), + 900: Color(0xFFB20F0F), + }); /// Color: #979797 static const Color gray410 = Color(0xFF979797); @@ -75,34 +73,30 @@ class MyColorName { /// 700: #FFD7821D /// 800: #FFD27817 /// 900: #FFCA670E - static const MaterialColor yellowOcher = MaterialColor( - 0xFFDF9527, - { - 50: Color(0xFFFBF2E5), - 100: Color(0xFFF5DFBE), - 200: Color(0xFFEFCA93), - 300: Color(0xFFE9B568), - 400: Color(0xFFE4A547), - 500: Color(0xFFDF9527), - 600: Color(0xFFDB8D23), - 700: Color(0xFFD7821D), - 800: Color(0xFFD27817), - 900: Color(0xFFCA670E), - }, - ); + static const MaterialColor yellowOcher = + MaterialColor(0xFFDF9527, { + 50: Color(0xFFFBF2E5), + 100: Color(0xFFF5DFBE), + 200: Color(0xFFEFCA93), + 300: Color(0xFFE9B568), + 400: Color(0xFFE4A547), + 500: Color(0xFFDF9527), + 600: Color(0xFFDB8D23), + 700: Color(0xFFD7821D), + 800: Color(0xFFD27817), + 900: Color(0xFFCA670E), + }); /// MaterialAccentColor: /// 100: #FFFFE8E0 /// 200: #FFFFBCA3 /// 400: #FFFFA989 /// 700: #FFFF9E7A - static const MaterialAccentColor yellowOcherAccent = MaterialAccentColor( - 0xFFFFBCA3, - { - 100: Color(0xFFFFE8E0), - 200: Color(0xFFFFBCA3), - 400: Color(0xFFFFA989), - 700: Color(0xFFFF9E7A), - }, - ); + static const MaterialAccentColor yellowOcherAccent = + MaterialAccentColor(0xFFFFBCA3, { + 100: Color(0xFFFFE8E0), + 200: Color(0xFFFFBCA3), + 400: Color(0xFFFFA989), + 700: Color(0xFFFF9E7A), + }); } diff --git a/examples/example_resources/lib/gen/assets.gen.dart b/examples/example_resources/lib/gen/assets.gen.dart index c4642f760..b25dc06f4 100644 --- a/examples/example_resources/lib/gen/assets.gen.dart +++ b/examples/example_resources/lib/gen/assets.gen.dart @@ -39,8 +39,14 @@ class $AssetsImagesGen { RiveGenImage get skills => const RiveGenImage('assets/images/skills.riv'); /// List of all assets - List get values => - [cat, dart, favorite, flutter3, runningCarOnRoad, skills]; + List get values => [ + cat, + dart, + favorite, + flutter3, + runningCarOnRoad, + skills, + ]; } class $AssetsUnknownGen { @@ -64,11 +70,7 @@ class ResAssets { } class AssetGenImage { - const AssetGenImage( - this._assetName, { - this.size, - this.flavors = const {}, - }); + const AssetGenImage(this._assetName, {this.size, this.flavors = const {}}); final String _assetName; @@ -136,11 +138,7 @@ class AssetGenImage { @Deprecated('Do not specify package for a generated library asset') String? package = package, }) { - return AssetImage( - _assetName, - bundle: bundle, - package: package, - ); + return AssetImage(_assetName, bundle: bundle, package: package); } String get path => _assetName; @@ -149,17 +147,11 @@ class AssetGenImage { } 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; + 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; @@ -216,7 +208,8 @@ class SvgGenImage { placeholderBuilder: placeholderBuilder, semanticsLabel: semanticsLabel, excludeFromSemantics: excludeFromSemantics, - colorFilter: colorFilter ?? + colorFilter: + colorFilter ?? (color == null ? null : ColorFilter.mode(color, colorBlendMode)), clipBehavior: clipBehavior, cacheColorFilter: cacheColorFilter, @@ -229,10 +222,7 @@ class SvgGenImage { } class RiveGenImage { - const RiveGenImage( - this._assetName, { - this.flavors = const {}, - }); + const RiveGenImage(this._assetName, {this.flavors = const {}}); final String _assetName; final Set flavors; @@ -272,10 +262,7 @@ class RiveGenImage { } class LottieGenImage { - const LottieGenImage( - this._assetName, { - this.flavors = const {}, - }); + const LottieGenImage(this._assetName, {this.flavors = const {}}); final String _assetName; final Set flavors; @@ -294,11 +281,8 @@ class LottieGenImage { _lottie.LottieImageProviderFactory? imageProviderFactory, Key? key, AssetBundle? bundle, - Widget Function( - BuildContext, - Widget, - _lottie.LottieComposition?, - )? frameBuilder, + Widget Function(BuildContext, Widget, _lottie.LottieComposition?)? + frameBuilder, ImageErrorWidgetBuilder? errorBuilder, double? width, double? height, diff --git a/packages/command/pubspec.yaml b/packages/command/pubspec.yaml index 4eb56bd9f..59ba3ce38 100644 --- a/packages/command/pubspec.yaml +++ b/packages/command/pubspec.yaml @@ -14,6 +14,7 @@ executables: dependencies: flutter_gen_core: 5.10.0 + args: ^2.0.0 dev_dependencies: diff --git a/packages/core/lib/generators/assets_generator.dart b/packages/core/lib/generators/assets_generator.dart index 3b0a32227..6e3afb9fb 100644 --- a/packages/core/lib/generators/assets_generator.dart +++ b/packages/core/lib/generators/assets_generator.dart @@ -63,6 +63,7 @@ Future generateAssets( ImageIntegration( config.packageParameterLiteral, parseMetadata: config.flutterGen.parseMetadata, + parseAnimation: config.flutterGen.images.parseAnimation, ), if (config.flutterGen.integrations.flutterSvg) SvgIntegration( diff --git a/packages/core/lib/generators/integrations/image_integration.dart b/packages/core/lib/generators/integrations/image_integration.dart index 11bc1e8e3..14dae7757 100644 --- a/packages/core/lib/generators/integrations/image_integration.dart +++ b/packages/core/lib/generators/integrations/image_integration.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:flutter_gen_core/generators/integrations/integration.dart'; +import 'package:image/image.dart' as img; import 'package:image_size_getter/file_input.dart'; import 'package:image_size_getter/image_size_getter.dart'; @@ -11,9 +12,12 @@ import 'package:image_size_getter/image_size_getter.dart'; class ImageIntegration extends Integration { ImageIntegration( String packageName, { + required this.parseAnimation, super.parseMetadata, }) : super(packageName); + final bool parseAnimation; + String get packageParameter => isPackage ? ' = package' : ''; String get keyName => @@ -32,6 +36,7 @@ class ImageIntegration extends Integration { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; @@ -40,6 +45,7 @@ ${isPackage ? "\n static const String package = '$packageName';" : ''} final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -109,6 +115,18 @@ ${isPackage ? "\n static const String package = '$packageName';" : ''} String get keyName => $keyName; } + +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} '''; @override @@ -116,12 +134,22 @@ ${isPackage ? "\n static const String package = '$packageName';" : ''} @override String classInstantiate(AssetType asset) { - final info = parseMetadata ? _getMetadata(asset) : null; + final info = parseMetadata || parseAnimation ? _getMetadata(asset) : null; final buffer = StringBuffer(className); buffer.write('('); buffer.write('\'${asset.posixStylePath}\''); if (info != null) { - buffer.write(', size: Size(${info.width}, ${info.height})'); + buffer.write(', size: const Size(${info.width}, ${info.height})'); + + if (info.animation case final animation?) { + buffer.write(', animation: const AssetGenImageAnimation('); + buffer.write('isAnimation: ${animation.frames > 1}'); + buffer.write( + ', duration: Duration(milliseconds: ${animation.duration.inMilliseconds})', + ); + buffer.write(', frames: ${animation.frames}'); + buffer.write(')'); + } } if (asset.flavors.isNotEmpty) { buffer.write(', flavors: {'); @@ -161,11 +189,54 @@ ${isPackage ? "\n static const String package = '$packageName';" : ''} FileInput(File(asset.fullPath)), ); final size = result.size; - return ImageMetadata(size.width.toDouble(), size.height.toDouble()); + final animation = parseAnimation ? _parseAnimation(asset) : null; + + return ImageMetadata( + width: size.width.toDouble(), + height: size.height.toDouble(), + animation: animation, + ); } catch (e) { stderr .writeln('[WARNING] Failed to parse \'${asset.path}\' metadata: $e'); } return null; } + + ImageAnimation? _parseAnimation(AssetType asset) { + try { + final decoder = switch (asset.mime) { + 'image/gif' => img.GifDecoder(), + 'image/webp' => img.WebPDecoder(), + _ => null, + }; + + if (decoder == null) { + return null; + } + + final file = File(asset.fullPath); + final bytes = file.readAsBytesSync(); + final image = decoder.decode(bytes); + + if (image == null) { + return null; + } + + return ImageAnimation( + frames: image.frames.length, + duration: Duration( + milliseconds: image.frames.fold( + 0, + (duration, frame) => duration + frame.frameDuration, + ), + ), + ); + } catch (e) { + stderr.writeln( + '[WARNING] Failed to parse \'${asset.path}\' animation information: $e', + ); + } + return null; + } } diff --git a/packages/core/lib/generators/integrations/integration.dart b/packages/core/lib/generators/integrations/integration.dart index b3c0dcff3..d6ddc8308 100644 --- a/packages/core/lib/generators/integrations/integration.dart +++ b/packages/core/lib/generators/integrations/integration.dart @@ -55,8 +55,24 @@ const String deprecationMessagePackage = /// Currently only contains the width and height, but could contain more in /// future. class ImageMetadata { - const ImageMetadata(this.width, this.height); + const ImageMetadata({ + required this.width, + required this.height, + this.animation, + }); final double width; final double height; + final ImageAnimation? animation; +} + +/// Metadata about the parsed animation file when [parseAnimation] is true. +class ImageAnimation { + const ImageAnimation({ + required this.frames, + required this.duration, + }); + + final int frames; + final Duration duration; } diff --git a/packages/core/lib/generators/integrations/svg_integration.dart b/packages/core/lib/generators/integrations/svg_integration.dart index 5b2ca7af2..c6dd5de0d 100644 --- a/packages/core/lib/generators/integrations/svg_integration.dart +++ b/packages/core/lib/generators/integrations/svg_integration.dart @@ -132,7 +132,10 @@ ${isPackage ? "\n static const String package = '$packageName';" : ''} // but it's also the same way it will be eventually rendered by Flutter. final svg = File(asset.fullPath).readAsStringSync(); final vec = parseWithoutOptimizers(svg); - return ImageMetadata(vec.width, vec.height); + return ImageMetadata( + width: vec.width, + height: vec.height, + ); } catch (e) { stderr.writeln( '[WARNING] Failed to parse SVG \'${asset.path}\' metadata: $e', diff --git a/packages/core/lib/settings/config_default.dart b/packages/core/lib/settings/config_default.dart index 396f2a857..0b6f804e6 100644 --- a/packages/core/lib/settings/config_default.dart +++ b/packages/core/lib/settings/config_default.dart @@ -15,6 +15,10 @@ flutter_gen: flutter_svg: false rive: false lottie: false + + images: + # Optional + parse_animation: false assets: # Optional diff --git a/packages/core/lib/settings/pubspec.dart b/packages/core/lib/settings/pubspec.dart index 480aaa5d2..d49020bdf 100644 --- a/packages/core/lib/settings/pubspec.dart +++ b/packages/core/lib/settings/pubspec.dart @@ -103,6 +103,7 @@ class FlutterGen { required this.output, required this.lineLength, required this.parseMetadata, + required this.images, required this.assets, required this.fonts, required this.integrations, @@ -120,6 +121,9 @@ class FlutterGen { @JsonKey(name: 'parse_metadata', required: true) final bool parseMetadata; + @JsonKey(name: 'images', required: true) + final FlutterGenImages images; + @JsonKey(name: 'assets', required: true) final FlutterGenAssets assets; @@ -185,6 +189,19 @@ class FlutterGenAssets { final List exclude; } +@JsonSerializable() +class FlutterGenImages { + const FlutterGenImages({ + required this.parseAnimation, + }); + + factory FlutterGenImages.fromJson(Map json) => + _$FlutterGenImagesFromJson(json); + + @JsonKey(name: 'parse_animation', required: true) + final bool parseAnimation; +} + @JsonSerializable() class FlutterGenFonts { const FlutterGenFonts({ diff --git a/packages/core/lib/settings/pubspec.g.dart b/packages/core/lib/settings/pubspec.g.dart index af71498b6..91c1ae47b 100644 --- a/packages/core/lib/settings/pubspec.g.dart +++ b/packages/core/lib/settings/pubspec.g.dart @@ -74,6 +74,7 @@ FlutterGen _$FlutterGenFromJson(Map json) => $checkedCreate( 'output', 'line_length', 'parse_metadata', + 'images', 'assets', 'fonts', 'integrations', @@ -83,6 +84,7 @@ FlutterGen _$FlutterGenFromJson(Map json) => $checkedCreate( 'output', 'line_length', 'parse_metadata', + 'images', 'assets', 'fonts', 'integrations', @@ -93,6 +95,8 @@ FlutterGen _$FlutterGenFromJson(Map json) => $checkedCreate( output: $checkedConvert('output', (v) => v as String), lineLength: $checkedConvert('line_length', (v) => (v as num).toInt()), parseMetadata: $checkedConvert('parse_metadata', (v) => v as bool), + images: $checkedConvert( + 'images', (v) => FlutterGenImages.fromJson(v as Map)), assets: $checkedConvert( 'assets', (v) => FlutterGenAssets.fromJson(v as Map)), fonts: $checkedConvert( @@ -162,6 +166,23 @@ FlutterGenAssets _$FlutterGenAssetsFromJson(Map json) => $checkedCreate( }, ); +FlutterGenImages _$FlutterGenImagesFromJson(Map json) => $checkedCreate( + 'FlutterGenImages', + json, + ($checkedConvert) { + $checkKeys( + json, + allowedKeys: const ['parse_animation'], + requiredKeys: const ['parse_animation'], + ); + final val = FlutterGenImages( + parseAnimation: $checkedConvert('parse_animation', (v) => v as bool), + ); + return val; + }, + fieldKeyMap: const {'parseAnimation': 'parse_animation'}, + ); + FlutterGenFonts _$FlutterGenFontsFromJson(Map json) => $checkedCreate( 'FlutterGenFonts', json, diff --git a/packages/core/lib/version.gen.dart b/packages/core/lib/version.gen.dart index e0a6a78d0..a5c517119 100644 --- a/packages/core/lib/version.gen.dart +++ b/packages/core/lib/version.gen.dart @@ -1,2 +1,2 @@ /// DO NOT MODIFY BY HAND, Generated by version_gen -String packageVersion = '5.10.0'; +String packageVersion = '5.11.0'; diff --git a/packages/core/pubspec.yaml b/packages/core/pubspec.yaml index cac92f9d7..55722ecaf 100644 --- a/packages/core/pubspec.yaml +++ b/packages/core/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: meta: ^1.7.0 path: ^1.8.0 yaml: ^3.0.0 - mime: '>=1.0.0 <3.0.0' + mime: ">=1.0.0 <3.0.0" xml: ^6.0.0 dartx: ^1.0.0 color: ^3.0.0 @@ -25,11 +25,12 @@ dependencies: glob: ^2.0.0 dart_style: ^3.0.0 - archive: '>=3.4.0 <5.0.0' + archive: ">=3.4.0 <5.0.0" args: ^2.0.0 pub_semver: ^2.0.0 vector_graphics_compiler: ^1.1.9 image_size_getter: ^2.4.0 + image: ^4.5.4 dev_dependencies: lints: any # Ignoring the version to allow editing across SDK versions. diff --git a/packages/core/test_resources/actual_data/assets_assets.gen.dart b/packages/core/test_resources/actual_data/assets_assets.gen.dart index ad262d4aa..9472272fb 100644 --- a/packages/core/test_resources/actual_data/assets_assets.gen.dart +++ b/packages/core/test_resources/actual_data/assets_assets.gen.dart @@ -162,12 +162,14 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -238,6 +240,18 @@ class AssetGenImage { String get keyName => _assetName; } +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} + class SvgGenImage { const SvgGenImage( this._assetName, { diff --git a/packages/core/test_resources/actual_data/assets_assets_camel_case.gen.dart b/packages/core/test_resources/actual_data/assets_assets_camel_case.gen.dart index 55d4e1679..f8a4c2b33 100644 --- a/packages/core/test_resources/actual_data/assets_assets_camel_case.gen.dart +++ b/packages/core/test_resources/actual_data/assets_assets_camel_case.gen.dart @@ -86,12 +86,14 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -161,3 +163,15 @@ class AssetGenImage { String get keyName => _assetName; } + +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} diff --git a/packages/core/test_resources/actual_data/assets_assets_change_class_name.gen.dart b/packages/core/test_resources/actual_data/assets_assets_change_class_name.gen.dart index cb88beb37..db301a01f 100644 --- a/packages/core/test_resources/actual_data/assets_assets_change_class_name.gen.dart +++ b/packages/core/test_resources/actual_data/assets_assets_change_class_name.gen.dart @@ -45,12 +45,14 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -120,3 +122,15 @@ class AssetGenImage { String get keyName => _assetName; } + +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} diff --git a/packages/core/test_resources/actual_data/assets_assets_directory_path.gen.dart b/packages/core/test_resources/actual_data/assets_assets_directory_path.gen.dart index 0221b8284..d6d565679 100644 --- a/packages/core/test_resources/actual_data/assets_assets_directory_path.gen.dart +++ b/packages/core/test_resources/actual_data/assets_assets_directory_path.gen.dart @@ -82,12 +82,14 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -158,6 +160,18 @@ class AssetGenImage { String get keyName => _assetName; } +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} + class SvgGenImage { const SvgGenImage( this._assetName, { diff --git a/packages/core/test_resources/actual_data/assets_assets_directory_path_with_package_parameter.gen.dart b/packages/core/test_resources/actual_data/assets_assets_directory_path_with_package_parameter.gen.dart index 952d29829..6b66394ef 100644 --- a/packages/core/test_resources/actual_data/assets_assets_directory_path_with_package_parameter.gen.dart +++ b/packages/core/test_resources/actual_data/assets_assets_directory_path_with_package_parameter.gen.dart @@ -85,6 +85,7 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; @@ -93,6 +94,7 @@ class AssetGenImage { final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -165,6 +167,18 @@ class AssetGenImage { String get keyName => 'packages/test/$_assetName'; } +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} + class SvgGenImage { const SvgGenImage( this._assetName, { diff --git a/packages/core/test_resources/actual_data/assets_assets_exclude_files.gen.dart b/packages/core/test_resources/actual_data/assets_assets_exclude_files.gen.dart index 9de8dd65c..81c5eafb6 100644 --- a/packages/core/test_resources/actual_data/assets_assets_exclude_files.gen.dart +++ b/packages/core/test_resources/actual_data/assets_assets_exclude_files.gen.dart @@ -75,12 +75,14 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -150,3 +152,15 @@ class AssetGenImage { String get keyName => _assetName; } + +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} diff --git a/packages/core/test_resources/actual_data/assets_assets_flavored.gen.dart b/packages/core/test_resources/actual_data/assets_assets_flavored.gen.dart index 68a76446e..972f5cdf2 100644 --- a/packages/core/test_resources/actual_data/assets_assets_flavored.gen.dart +++ b/packages/core/test_resources/actual_data/assets_assets_flavored.gen.dart @@ -164,12 +164,14 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -240,6 +242,18 @@ class AssetGenImage { String get keyName => _assetName; } +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} + class SvgGenImage { const SvgGenImage( this._assetName, { diff --git a/packages/core/test_resources/actual_data/assets_assets_no_integrations.gen.dart b/packages/core/test_resources/actual_data/assets_assets_no_integrations.gen.dart index 619b60a87..87f6e3cb3 100644 --- a/packages/core/test_resources/actual_data/assets_assets_no_integrations.gen.dart +++ b/packages/core/test_resources/actual_data/assets_assets_no_integrations.gen.dart @@ -120,12 +120,14 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -195,3 +197,15 @@ class AssetGenImage { String get keyName => _assetName; } + +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} diff --git a/packages/core/test_resources/actual_data/assets_assets_package_parameter.gen.dart b/packages/core/test_resources/actual_data/assets_assets_package_parameter.gen.dart index 220ba51e1..e342b9b84 100644 --- a/packages/core/test_resources/actual_data/assets_assets_package_parameter.gen.dart +++ b/packages/core/test_resources/actual_data/assets_assets_package_parameter.gen.dart @@ -73,6 +73,7 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; @@ -81,6 +82,7 @@ class AssetGenImage { final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -153,6 +155,18 @@ class AssetGenImage { String get keyName => 'packages/test/$_assetName'; } +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} + class SvgGenImage { const SvgGenImage( this._assetName, { diff --git a/packages/core/test_resources/actual_data/assets_assets_package_parameter_disable_null_safety.gen.dart b/packages/core/test_resources/actual_data/assets_assets_package_parameter_disable_null_safety.gen.dart index 213b0f64b..e15d95ece 100644 --- a/packages/core/test_resources/actual_data/assets_assets_package_parameter_disable_null_safety.gen.dart +++ b/packages/core/test_resources/actual_data/assets_assets_package_parameter_disable_null_safety.gen.dart @@ -61,6 +61,7 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; @@ -69,6 +70,7 @@ class AssetGenImage { final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -141,6 +143,18 @@ class AssetGenImage { String get keyName => 'packages/test/$_assetName'; } +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} + class SvgGenImage { const SvgGenImage( this._assetName, { diff --git a/packages/core/test_resources/actual_data/assets_assets_parse_metadata.gen.dart b/packages/core/test_resources/actual_data/assets_assets_parse_metadata.gen.dart index 44aa4f2b7..0c9e7aa42 100644 --- a/packages/core/test_resources/actual_data/assets_assets_parse_metadata.gen.dart +++ b/packages/core/test_resources/actual_data/assets_assets_parse_metadata.gen.dart @@ -17,7 +17,7 @@ class $PicturesGen { /// File path: pictures/chip5.jpg AssetGenImage get chip5 => - const AssetGenImage('pictures/chip5.jpg', size: Size(600.0, 403.0)); + const AssetGenImage('pictures/chip5.jpg', size: const Size(600.0, 403.0)); /// List of all assets List get values => [chip5]; @@ -36,9 +36,12 @@ class $AssetsFlareGen { class $AssetsImagesGen { const $AssetsImagesGen(); + /// Directory path: assets/images/animated + $AssetsImagesAnimatedGen get animated => const $AssetsImagesAnimatedGen(); + /// File path: assets/images/chip1.jpg - AssetGenImage get chip1 => - const AssetGenImage('assets/images/chip1.jpg', size: Size(600.0, 403.0)); + AssetGenImage get chip1 => const AssetGenImage('assets/images/chip1.jpg', + size: const Size(600.0, 403.0)); /// File path: assets/images/chip2.jpg AssetGenImage get chip2 => const AssetGenImage('assets/images/chip2.jpg'); @@ -53,8 +56,8 @@ class $AssetsImagesGen { $AssetsImagesIconsGen get icons => const $AssetsImagesIconsGen(); /// File path: assets/images/logo.png - AssetGenImage get logo => - const AssetGenImage('assets/images/logo.png', size: Size(209.0, 49.0)); + AssetGenImage get logo => const AssetGenImage('assets/images/logo.png', + size: const Size(209.0, 49.0)); /// File path: assets/images/profile.jpg AssetGenImage get profileJpg => @@ -102,13 +105,29 @@ class $AssetsUnknownGen { List get values => [unknownMimeType]; } +class $AssetsImagesAnimatedGen { + const $AssetsImagesAnimatedGen(); + + /// File path: assets/images/animated/emoji_hugging_face.webp + AssetGenImage get emojiHuggingFace => + const AssetGenImage('assets/images/animated/emoji_hugging_face.webp', + size: const Size(512.0, 512.0), + animation: const AssetGenImageAnimation( + isAnimation: true, + duration: Duration(milliseconds: 2970), + frames: 45)); + + /// List of all assets + List get values => [emojiHuggingFace]; +} + class $AssetsImagesChip3Gen { const $AssetsImagesChip3Gen(); /// File path: assets/images/chip3/chip3.jpg AssetGenImage get chip3 => const AssetGenImage('assets/images/chip3/chip3.jpg', - size: Size(600.0, 403.0)); + size: const Size(600.0, 403.0)); /// List of all assets List get values => [chip3]; @@ -120,7 +139,7 @@ class $AssetsImagesChip4Gen { /// File path: assets/images/chip4/chip4.jpg AssetGenImage get chip4 => const AssetGenImage('assets/images/chip4/chip4.jpg', - size: Size(600.0, 403.0)); + size: const Size(600.0, 403.0)); /// List of all assets List get values => [chip4]; @@ -171,12 +190,14 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -247,6 +268,18 @@ class AssetGenImage { String get keyName => _assetName; } +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} + class SvgGenImage { const SvgGenImage( this._assetName, { diff --git a/packages/core/test_resources/actual_data/assets_assets_snake_case.gen.dart b/packages/core/test_resources/actual_data/assets_assets_snake_case.gen.dart index e6c001da6..0ba76e83d 100644 --- a/packages/core/test_resources/actual_data/assets_assets_snake_case.gen.dart +++ b/packages/core/test_resources/actual_data/assets_assets_snake_case.gen.dart @@ -87,12 +87,14 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -162,3 +164,15 @@ class AssetGenImage { String get keyName => _assetName; } + +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} diff --git a/packages/core/test_resources/actual_data/assets_change_output_path.gen.dart b/packages/core/test_resources/actual_data/assets_change_output_path.gen.dart index ed1a50c5a..3f71ee399 100644 --- a/packages/core/test_resources/actual_data/assets_change_output_path.gen.dart +++ b/packages/core/test_resources/actual_data/assets_change_output_path.gen.dart @@ -45,12 +45,14 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -120,3 +122,15 @@ class AssetGenImage { String get keyName => _assetName; } + +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} diff --git a/packages/core/test_resources/actual_data/assets_exclude_files.gen.dart b/packages/core/test_resources/actual_data/assets_exclude_files.gen.dart new file mode 100644 index 000000000..4537d5b23 --- /dev/null +++ b/packages/core/test_resources/actual_data/assets_exclude_files.gen.dart @@ -0,0 +1,151 @@ +/// 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:flutter/widgets.dart'; + +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 $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/chip4 + $AssetsImagesChip4Gen get chip4 => const $AssetsImagesChip4Gen(); + + /// File path: assets/images/profile.jpg + AssetGenImage get profile => const AssetGenImage('assets/images/profile.jpg'); + + /// List of all assets + List get values => [chip1, chip2, profile]; +} + +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 $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 Assets { + const Assets._(); + + static const $AssetsImagesGen images = $AssetsImagesGen(); + static const $AssetsJsonGen json = $AssetsJsonGen(); + static const $PicturesGen pictures = $PicturesGen(); +} + +class AssetGenImage { + const AssetGenImage( + this._assetName, { + this.size, + this.flavors = const {}, + this.isAnimation = false, + this.duration = Duration.zero, + this.frames = 1, + }); + + final String _assetName; + + final Size? size; + final Set flavors; + final bool isAnimation; + final Duration duration; + final int frames; + + 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 = true, + bool isAntiAlias = false, + String? package, + FilterQuality filterQuality = FilterQuality.medium, + 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; +} diff --git a/packages/core/test_resources/actual_data/assets_normal.gen.dart b/packages/core/test_resources/actual_data/assets_normal.gen.dart index f8180f894..68c22191d 100644 --- a/packages/core/test_resources/actual_data/assets_normal.gen.dart +++ b/packages/core/test_resources/actual_data/assets_normal.gen.dart @@ -125,12 +125,14 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -201,6 +203,18 @@ class AssetGenImage { String get keyName => _assetName; } +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} + class SvgGenImage { const SvgGenImage( this._assetName, { diff --git a/packages/core/test_resources/actual_data/assets_only_flutter_value.gen.dart b/packages/core/test_resources/actual_data/assets_only_flutter_value.gen.dart index ed1a50c5a..3f71ee399 100644 --- a/packages/core/test_resources/actual_data/assets_only_flutter_value.gen.dart +++ b/packages/core/test_resources/actual_data/assets_only_flutter_value.gen.dart @@ -45,12 +45,14 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -120,3 +122,15 @@ class AssetGenImage { String get keyName => _assetName; } + +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} diff --git a/packages/core/test_resources/actual_data/assets_package_parameter_disable_null_safety.gen.dart b/packages/core/test_resources/actual_data/assets_package_parameter_disable_null_safety.gen.dart new file mode 100644 index 000000000..c367d2e7b --- /dev/null +++ b/packages/core/test_resources/actual_data/assets_package_parameter_disable_null_safety.gen.dart @@ -0,0 +1,219 @@ +/// 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: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 $AssetsImagesGen { + const $AssetsImagesGen(); + + /// Directory path: assets/images/chip3 + $AssetsImagesChip3Gen get chip3 => const $AssetsImagesChip3Gen(); + + /// Directory path: assets/images/icons + $AssetsImagesIconsGen get icons => const $AssetsImagesIconsGen(); +} + +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 $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'); + + /// List of all assets + List get values => [dartTest, fuchsia]; +} + +class Assets { + const Assets._(); + + static const String package = 'test'; + + static const $AssetsImagesGen images = $AssetsImagesGen(); +} + +class AssetGenImage { + const AssetGenImage( + this._assetName, { + this.size, + this.flavors = const {}, + this.isAnimation = false, + this.duration = Duration.zero, + this.frames = 1, + }); + + final String _assetName; + + static const String package = 'test'; + + final Size? size; + final Set flavors; + final bool isAnimation; + final Duration duration; + final int frames; + + 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 = true, + bool isAntiAlias = false, + @Deprecated('Do not specify package for a generated library asset') + String? package = package, + FilterQuality filterQuality = FilterQuality.medium, + 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, + @Deprecated('Do not specify package for a generated library asset') + String? package = package, + }) { + return AssetImage(_assetName, bundle: bundle, package: package); + } + + String get path => _assetName; + + String get keyName => 'packages/test/$_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; + + static const String package = 'test'; + + _svg.SvgPicture svg({ + Key? key, + bool matchTextDirection = false, + AssetBundle? bundle, + @Deprecated('Do not specify package for a generated library asset') + String? package = 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 => 'packages/test/$_assetName'; +} diff --git a/packages/core/test_resources/actual_data/assets_wrong_output_path.gen.dart b/packages/core/test_resources/actual_data/assets_wrong_output_path.gen.dart index ed1a50c5a..3f71ee399 100644 --- a/packages/core/test_resources/actual_data/assets_wrong_output_path.gen.dart +++ b/packages/core/test_resources/actual_data/assets_wrong_output_path.gen.dart @@ -45,12 +45,14 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -120,3 +122,15 @@ class AssetGenImage { String get keyName => _assetName; } + +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} diff --git a/packages/core/test_resources/actual_data/build_assets_build_assets.gen.dart b/packages/core/test_resources/actual_data/build_assets_build_assets.gen.dart index cc9594706..8aec833df 100644 --- a/packages/core/test_resources/actual_data/build_assets_build_assets.gen.dart +++ b/packages/core/test_resources/actual_data/build_assets_build_assets.gen.dart @@ -155,12 +155,14 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -231,6 +233,18 @@ class AssetGenImage { String get keyName => _assetName; } +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} + class SvgGenImage { const SvgGenImage( this._assetName, { diff --git a/packages/core/test_resources/actual_data/build_assets_build_empty.gen.dart b/packages/core/test_resources/actual_data/build_assets_build_empty.gen.dart index ad262d4aa..9472272fb 100644 --- a/packages/core/test_resources/actual_data/build_assets_build_empty.gen.dart +++ b/packages/core/test_resources/actual_data/build_assets_build_empty.gen.dart @@ -162,12 +162,14 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -238,6 +240,18 @@ class AssetGenImage { String get keyName => _assetName; } +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} + class SvgGenImage { const SvgGenImage( this._assetName, { diff --git a/packages/core/test_resources/actual_data/build_assets_build_runner_assets.gen.dart b/packages/core/test_resources/actual_data/build_assets_build_runner_assets.gen.dart index b056259ca..16a4af406 100644 --- a/packages/core/test_resources/actual_data/build_assets_build_runner_assets.gen.dart +++ b/packages/core/test_resources/actual_data/build_assets_build_runner_assets.gen.dart @@ -155,12 +155,14 @@ class AssetGenImage { this._assetName, { this.size, this.flavors = const {}, + this.animation, }); final String _assetName; final Size? size; final Set flavors; + final AssetGenImageAnimation? animation; Image image({ Key? key, @@ -231,6 +233,18 @@ class AssetGenImage { String get keyName => _assetName; } +class AssetGenImageAnimation { + const AssetGenImageAnimation({ + required this.isAnimation, + required this.duration, + required this.frames, + }); + + final bool isAnimation; + final Duration duration; + final int frames; +} + class SvgGenImage { const SvgGenImage( this._assetName, { diff --git a/packages/core/test_resources/assets/images/animated/emoji_hugging_face.webp b/packages/core/test_resources/assets/images/animated/emoji_hugging_face.webp new file mode 100644 index 000000000..87972d9e4 Binary files /dev/null and b/packages/core/test_resources/assets/images/animated/emoji_hugging_face.webp differ diff --git a/packages/core/test_resources/pubspec_assets_parse_metadata.yaml b/packages/core/test_resources/pubspec_assets_parse_metadata.yaml index 189de2691..c084209ec 100644 --- a/packages/core/test_resources/pubspec_assets_parse_metadata.yaml +++ b/packages/core/test_resources/pubspec_assets_parse_metadata.yaml @@ -5,6 +5,9 @@ flutter_gen: line_length: 80 # Optional (default: 80) parse_metadata: true # Optional (default: false) + images: + parse_animation: true # Optional (default: false) + integrations: flutter_svg: true @@ -24,3 +27,4 @@ flutter: - assets/flare/ - assets/movie/ - assets/unknown/unknown_mime_type.bk + - assets/images/animated diff --git a/packages/runner/lib/flutter_gen_runner.dart b/packages/runner/lib/flutter_gen_runner.dart index e46d58e52..410fc0020 100644 --- a/packages/runner/lib/flutter_gen_runner.dart +++ b/packages/runner/lib/flutter_gen_runner.dart @@ -34,39 +34,39 @@ class FlutterGenBuilder extends Builder { @override Future build(BuildStep buildStep) async { - if (_config == null) { - return; - } - final state = await _createState(_config, buildStep); - if (state.shouldSkipGenerate(_currentState)) { - return; + if (_config case final config?) { + final state = await _createState(config, buildStep); + if (state.shouldSkipGenerate(_currentState)) { + return; + } + _currentState = state; + + await generator.build( + config: config, + writer: (contents, path) { + buildStep.writeAsString(_output(buildStep, path), contents); + }, + ); } - _currentState = state; - - await generator.build( - config: _config, - writer: (contents, path) { - buildStep.writeAsString(_output(buildStep, path), contents); - }, - ); } @override Map> get buildExtensions { - if (_config == null) { + if (_config case final config?) { + final output = config.pubspec.flutterGen.output; + return { + r'$package$': [ + for (final name in [ + generator.assetsName, + generator.colorsName, + generator.fontsName, + ]) + join(output, name), + ], + }; + } else { return {}; } - final output = _config.pubspec.flutterGen.output; - return { - r'$package$': [ - for (final name in [ - generator.assetsName, - generator.colorsName, - generator.fontsName, - ]) - join(output, name), - ], - }; } Future<_FlutterGenBuilderState> _createState(