Skip to content

Commit 946fd5f

Browse files
authored
✨ Adds .lottie support (#621)
## What does this change? Resolves #505 ## Type of change - [x] New feature (non-breaking change which adds functionality) - [x] This change requires a documentation update
1 parent 5ad4f6c commit 946fd5f

File tree

7 files changed

+31
-17
lines changed

7 files changed

+31
-17
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,11 @@ Widget build(BuildContext context) {
394394

395395
**Available Integrations**
396396

397-
| Packages | File extension | Setting | Usage |
398-
|---------------------------------------------------------|----------------|-----------------------|-------------------------------------------|
399-
| [flutter_svg](https://pub.dev/packages/flutter_svg) | .svg | `flutter_svg: true` | Assets.images.icons.paint.**svg()** |
400-
| [rive](https://pub.dev/packages/rive) | .riv | `rive: true` | Assets.rive.vehicles.**rive()** |
401-
| [lottie](https://pub.dev/packages/lottie) | .json, .zip | `lottie: true` | Assets.lottie.hamburgerArrow.**lottie()** |
397+
| Packages | File extension | Setting | Usage |
398+
|---------------------------------------------------------|----------------------|-----------------------|-------------------------------------------|
399+
| [flutter_svg](https://pub.dev/packages/flutter_svg) | .svg | `flutter_svg: true` | Assets.images.icons.paint.**svg()** |
400+
| [rive](https://pub.dev/packages/rive) | .riv | `rive: true` | Assets.rive.vehicles.**rive()** |
401+
| [lottie](https://pub.dev/packages/lottie) | .json, .zip, .lottie | `lottie: true` | Assets.lottie.hamburgerArrow.**lottie()** |
402402

403403
In other cases, the asset is generated as String class.
404404

19.7 KB
Binary file not shown.

examples/example/lib/gen/assets.gen.dart

+10-5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class $AssetsJsonGen {
7474
class $AssetsLottieGen {
7575
const $AssetsLottieGen();
7676

77+
/// File path: assets/lottie/XuiIZ9X1Rf.lottie
78+
LottieGenImage get xuiIZ9X1Rf =>
79+
const LottieGenImage('assets/lottie/XuiIZ9X1Rf.lottie');
80+
7781
/// File path: assets/lottie/alarm-clock-lottie-v440.json
7882
LottieGenImage get alarmClockLottieV440 =>
7983
const LottieGenImage('assets/lottie/alarm-clock-lottie-v440.json');
@@ -95,11 +99,12 @@ class $AssetsLottieGen {
9599

96100
/// List of all assets
97101
List<LottieGenImage> get values => [
98-
alarmClockLottieV440,
99-
geometricalAnimation,
100-
hamburgerArrow,
101-
spinningCarrousel
102-
];
102+
xuiIZ9X1Rf,
103+
alarmClockLottieV440,
104+
geometricalAnimation,
105+
hamburgerArrow,
106+
spinningCarrousel,
107+
];
103108
}
104109

105110
class $AssetsMixGen {

packages/core/lib/generators/integrations/lottie_integration.dart

+9-6
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,15 @@ ${isPackage ? "\n static const String package = '$packageName';" : ''}
116116
@override
117117
bool get isConstConstructor => true;
118118

119-
bool isLottieFile(AssetType type) {
120-
if (!_supportedMimeTypes.contains(type.mime)) {
119+
bool isLottieFile(AssetType asset) {
120+
if (asset.extension == '.lottie') {
121+
return true;
122+
}
123+
if (!_supportedMimeTypes.contains(asset.mime)) {
121124
return false;
122125
}
123-
if (type.mime == 'application/zip') {
124-
final inputStream = InputFileStream(type.fullPath);
126+
if (asset.mime == 'application/zip') {
127+
final inputStream = InputFileStream(asset.fullPath);
125128
final archive = ZipDecoder().decodeBuffer(inputStream);
126129
final jsonFile = archive.files.firstWhereOrNull(
127130
(e) => e.name.endsWith('.json'),
@@ -130,9 +133,9 @@ ${isPackage ? "\n static const String package = '$packageName';" : ''}
130133
return false;
131134
}
132135
final content = utf8.decode(jsonFile!.content);
133-
return _isValidJsonFile(type, overrideInput: content);
136+
return _isValidJsonFile(asset, overrideInput: content);
134137
}
135-
return _isValidJsonFile(type);
138+
return _isValidJsonFile(asset);
136139
}
137140

138141
bool _isValidJsonFile(AssetType type, {String? overrideInput}) {

packages/core/test_resources/actual_data/assets_lottie_integrations.gen.dart

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

packages/core/test_resources/pubspec_assets_lottie_integrations.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ flutter:
1111
assets:
1212
- assets/lottie/hamburger_arrow.json
1313
- assets/lottie/spinning_carrousel.zip
14+
- assets/lottie/XuiIZ9X1Rf.lottie

0 commit comments

Comments
 (0)