diff --git a/README.md b/README.md index 2e674ae44..076bc4dd7 100644 --- a/README.md +++ b/README.md @@ -410,6 +410,8 @@ Widget build(BuildContext context) { | [rive](https://pub.dev/packages/rive) | .riv | `rive: true` | Assets.rive.vehicles.**rive()** | | [lottie](https://pub.dev/packages/lottie) | .json, .zip, .lottie | `lottie: true` | Assets.lottie.hamburgerArrow.**lottie()** | +**Note:** For [lottie](https://pub.dev/packages/lottie) integration with `.lottie` files, you must add a custom decoder via `decoder` parameter to select the correct .json file from a dotlottie (.lottie) archive, see [lottie's document](https://pub.dev/packages/lottie#telegram-stickers-tgs-and-dotlottie-lottie) for more information. + In other cases, the asset is generated as String class. ```dart diff --git a/examples/example/lib/gen/assets.gen.dart b/examples/example/lib/gen/assets.gen.dart index 21a2ef0a6..57d68250b 100644 --- a/examples/example/lib/gen/assets.gen.dart +++ b/examples/example/lib/gen/assets.gen.dart @@ -215,7 +215,7 @@ class $AssetsLottieWrongGen { } class MyAssets { - MyAssets._(); + const MyAssets._(); static const String readme = 'README.md'; static const $AssetsFlareGen flare = $AssetsFlareGen(); @@ -465,6 +465,9 @@ class LottieGenImage { bool? addRepaintBoundary, FilterQuality? filterQuality, void Function(String)? onWarning, + _lottie.LottieDecoder? decoder, + _lottie.RenderCache? renderCache, + bool? backgroundLoading, }) { return _lottie.Lottie.asset( _assetName, @@ -489,6 +492,9 @@ class LottieGenImage { addRepaintBoundary: addRepaintBoundary, filterQuality: filterQuality, onWarning: onWarning, + decoder: decoder, + renderCache: renderCache, + backgroundLoading: backgroundLoading, ); } diff --git a/examples/example/pubspec.yaml b/examples/example/pubspec.yaml index 435c5e156..4036ecf8d 100644 --- a/examples/example/pubspec.yaml +++ b/examples/example/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: path: ../example_resources flutter_svg: ^2.0.0 - lottie: ^2.0.0 + lottie: ^3.0.0 rive: ^0.11.0 dev_dependencies: diff --git a/examples/example_resources/lib/gen/assets.gen.dart b/examples/example_resources/lib/gen/assets.gen.dart index 5e7aa6b9d..a5ac96f12 100644 --- a/examples/example_resources/lib/gen/assets.gen.dart +++ b/examples/example_resources/lib/gen/assets.gen.dart @@ -305,6 +305,9 @@ class LottieGenImage { bool? addRepaintBoundary, FilterQuality? filterQuality, void Function(String)? onWarning, + _lottie.LottieDecoder? decoder, + _lottie.RenderCache? renderCache, + bool? backgroundLoading, }) { return _lottie.Lottie.asset( _assetName, @@ -329,6 +332,9 @@ class LottieGenImage { addRepaintBoundary: addRepaintBoundary, filterQuality: filterQuality, onWarning: onWarning, + decoder: decoder, + renderCache: renderCache, + backgroundLoading: backgroundLoading, ); } diff --git a/examples/example_resources/pubspec.yaml b/examples/example_resources/pubspec.yaml index 2bbe95775..c35de09ff 100644 --- a/examples/example_resources/pubspec.yaml +++ b/examples/example_resources/pubspec.yaml @@ -11,7 +11,7 @@ dependencies: sdk: flutter flutter_svg: ^2.0.0 - lottie: ^2.0.0 + lottie: ^3.0.0 rive: ^0.11.0 dev_dependencies: diff --git a/packages/core/lib/generators/integrations/lottie_integration.dart b/packages/core/lib/generators/integrations/lottie_integration.dart index 59ad246bf..98ebf957d 100644 --- a/packages/core/lib/generators/integrations/lottie_integration.dart +++ b/packages/core/lib/generators/integrations/lottie_integration.dart @@ -74,6 +74,9 @@ ${isPackage ? "\n static const String package = '$packageName';" : ''} bool? addRepaintBoundary, FilterQuality? filterQuality, void Function(String)? onWarning, + _lottie.LottieDecoder? decoder, + _lottie.RenderCache? renderCache, + bool? backgroundLoading, }) { return _lottie.Lottie.asset( _assetName, @@ -98,6 +101,9 @@ ${isPackage ? "\n static const String package = '$packageName';" : ''} addRepaintBoundary: addRepaintBoundary, filterQuality: filterQuality, onWarning: onWarning, + decoder: decoder, + renderCache: renderCache, + backgroundLoading: backgroundLoading, ); } diff --git a/packages/core/test_resources/actual_data/assets_lottie_integrations.gen.dart b/packages/core/test_resources/actual_data/assets_lottie_integrations.gen.dart index 0497f0aa8..1cef9d7f6 100644 --- a/packages/core/test_resources/actual_data/assets_lottie_integrations.gen.dart +++ b/packages/core/test_resources/actual_data/assets_lottie_integrations.gen.dart @@ -26,11 +26,8 @@ class $AssetsLottieGen { const LottieGenImage('assets/lottie/spinning_carrousel.zip'); /// List of all assets - List get values => [ - xuiIZ9X1Rf, - hamburgerArrow, - spinningCarrousel, - ]; + List get values => + [xuiIZ9X1Rf, hamburgerArrow, spinningCarrousel]; } class Assets { @@ -40,7 +37,10 @@ class Assets { } class LottieGenImage { - const LottieGenImage(this._assetName, {this.flavors = const {}}); + const LottieGenImage( + this._assetName, { + this.flavors = const {}, + }); final String _assetName; final Set flavors; @@ -57,8 +57,11 @@ 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, @@ -68,6 +71,9 @@ class LottieGenImage { bool? addRepaintBoundary, FilterQuality? filterQuality, void Function(String)? onWarning, + _lottie.LottieDecoder? decoder, + _lottie.RenderCache? renderCache, + bool? backgroundLoading, }) { return _lottie.Lottie.asset( _assetName, @@ -92,6 +98,9 @@ class LottieGenImage { addRepaintBoundary: addRepaintBoundary, filterQuality: filterQuality, onWarning: onWarning, + decoder: decoder, + renderCache: renderCache, + backgroundLoading: backgroundLoading, ); } diff --git a/packages/core/test_resources/actual_data/assets_no_integrations.gen.dart b/packages/core/test_resources/actual_data/assets_no_integrations.gen.dart index 49a712941..619b60a87 100644 --- a/packages/core/test_resources/actual_data/assets_no_integrations.gen.dart +++ b/packages/core/test_resources/actual_data/assets_no_integrations.gen.dart @@ -49,13 +49,8 @@ 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 { @@ -121,7 +116,11 @@ class Assets { } class AssetGenImage { - const AssetGenImage(this._assetName, {this.size, this.flavors = const {}}); + const AssetGenImage( + this._assetName, { + this.size, + this.flavors = const {}, + }); final String _assetName; @@ -181,8 +180,15 @@ 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; diff --git a/packages/core/test_resources/actual_data/build_assets.gen.dart b/packages/core/test_resources/actual_data/build_assets.gen.dart index a9b4e838b..ad262d4aa 100644 --- a/packages/core/test_resources/actual_data/build_assets.gen.dart +++ b/packages/core/test_resources/actual_data/build_assets.gen.dart @@ -158,7 +158,11 @@ class Assets { } class AssetGenImage { - const AssetGenImage(this._assetName, {this.size, this.flavors = const {}}); + const AssetGenImage( + this._assetName, { + this.size, + this.flavors = const {}, + }); final String _assetName; @@ -218,8 +222,15 @@ 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; @@ -228,11 +239,17 @@ 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; @@ -261,11 +278,18 @@ class SvgGenImage { }) { final _svg.BytesLoader loader; if (_isVecFormat) { - loader = _vg.AssetBytesLoader(_assetName, - assetBundle: bundle, packageName: package); + loader = _vg.AssetBytesLoader( + _assetName, + assetBundle: bundle, + packageName: package, + ); } else { - loader = _svg.SvgAssetLoader(_assetName, - assetBundle: bundle, packageName: package, theme: theme); + loader = _svg.SvgAssetLoader( + _assetName, + assetBundle: bundle, + packageName: package, + theme: theme, + ); } return _svg.SvgPicture( loader,