Skip to content

Commit 9a81d26

Browse files
committed
Add support Telegram Sticker .tgs in Lottie Integration
1 parent 74b1d87 commit 9a81d26

File tree

10 files changed

+48
-33
lines changed

10 files changed

+48
-33
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,9 @@ Widget build(BuildContext context) {
408408
|---------------------------------------------------------|----------------------|-----------------------|-------------------------------------------|
409409
| [flutter_svg](https://pub.dev/packages/flutter_svg) | .svg | `flutter_svg: true` | Assets.images.icons.paint.**svg()** |
410410
| [rive](https://pub.dev/packages/rive) | .riv | `rive: true` | Assets.rive.vehicles.**rive()** |
411-
| [lottie](https://pub.dev/packages/lottie) | .json, .zip, .lottie | `lottie: true` | Assets.lottie.hamburgerArrow.**lottie()** |
411+
| [lottie](https://pub.dev/packages/lottie) | .json, .zip, .lottie, .tgs | `lottie: true` | Assets.lottie.hamburgerArrow.**lottie()** |
412412

413-
**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.
413+
**Note:** For [lottie](https://pub.dev/packages/lottie) integration with `.lottie` and `.tgs` files, you must add a custom decoder via `decoder` parameter, see [lottie's document](https://pub.dev/packages/lottie#telegram-stickers-tgs-and-dotlottie-lottie) for more information.
414414

415415
In other cases, the asset is generated as String class.
416416

25.4 KB
Binary file not shown.

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

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ class $AssetsImagesGen {
5454
const AssetGenImage('assets/images/profile.png');
5555

5656
/// List of all assets
57-
List<AssetGenImage> get values =>
58-
[chip1, chip2, logo, profileJpg, profilePng];
57+
List<AssetGenImage> get values => [
58+
chip1,
59+
chip2,
60+
logo,
61+
profileJpg,
62+
profilePng,
63+
];
5964
}
6065

6166
class $AssetsJsonGen {
@@ -82,6 +87,9 @@ class $AssetsLottieGen {
8287
LottieGenImage get alarmClockLottieV440 =>
8388
const LottieGenImage('assets/lottie/alarm-clock-lottie-v440.json');
8489

90+
/// File path: assets/lottie/cat.tgs
91+
LottieGenImage get cat => const LottieGenImage('assets/lottie/cat.tgs');
92+
8593
/// File path: assets/lottie/geometrical-animation.json
8694
LottieGenImage get geometricalAnimation =>
8795
const LottieGenImage('assets/lottie/geometrical-animation.json');
@@ -101,6 +109,7 @@ class $AssetsLottieGen {
101109
List<LottieGenImage> get values => [
102110
xuiIZ9X1Rf,
103111
alarmClockLottieV440,
112+
cat,
104113
geometricalAnimation,
105114
hamburgerArrow,
106115
spinningCarrousel,
@@ -171,10 +180,8 @@ class $AssetsImagesChip4Gen {
171180
const $AssetsImagesChip4Gen();
172181

173182
/// File path: assets/images/chip4/chip4.jpg
174-
AssetGenImage get chip4 => const AssetGenImage(
175-
'assets/images/chip4/chip4.jpg',
176-
flavors: {'extern'},
177-
);
183+
AssetGenImage get chip4 =>
184+
const AssetGenImage('assets/images/chip4/chip4.jpg', flavors: {'extern'});
178185

179186
/// List of all assets
180187
List<AssetGenImage> get values => [chip4];
@@ -232,11 +239,7 @@ class MyAssets {
232239
}
233240

234241
class AssetGenImage {
235-
const AssetGenImage(
236-
this._assetName, {
237-
this.size,
238-
this.flavors = const {},
239-
});
242+
const AssetGenImage(this._assetName, {this.size, this.flavors = const {}});
240243

241244
final String _assetName;
242245

@@ -296,15 +299,8 @@ class AssetGenImage {
296299
);
297300
}
298301

299-
ImageProvider provider({
300-
AssetBundle? bundle,
301-
String? package,
302-
}) {
303-
return AssetImage(
304-
_assetName,
305-
bundle: bundle,
306-
package: package,
307-
);
302+
ImageProvider provider({AssetBundle? bundle, String? package}) {
303+
return AssetImage(_assetName, bundle: bundle, package: package);
308304
}
309305

310306
String get path => _assetName;

examples/example/lib/main.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:example/gen/colors.gen.dart';
33
import 'package:example/gen/fonts.gen.dart';
44
import 'package:example_resources/gen/assets.gen.dart';
55
import 'package:flutter/material.dart';
6+
import 'package:lottie/lottie.dart';
67

78
void main() {
89
print(MyAssets.images.chip4.chip4.flavors);
@@ -59,6 +60,13 @@ class MyApp extends StatelessWidget {
5960
fit: BoxFit.contain,
6061
),
6162
),
63+
SizedBox(
64+
width: 200,
65+
height: 200,
66+
child: MyAssets.lottie.cat.lottie(
67+
decoder: LottieComposition.decodeGZip,
68+
),
69+
),
6270
MyAssets.images.chip1.image(),
6371
Container(
6472
height: 400,
25.4 KB
Binary file not shown.

examples/example_resources/lib/gen/assets.gen.dart

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ import 'package:vector_graphics/vector_graphics.dart' as _vg;
1717
class $AssetsImagesGen {
1818
const $AssetsImagesGen();
1919

20+
/// File path: assets/images/cat.tgs
21+
LottieGenImage get cat => const LottieGenImage('assets/images/cat.tgs');
22+
2023
/// File path: assets/images/dart.svg
2124
SvgGenImage get dart => const SvgGenImage('assets/images/dart.svg');
2225

2326
/// File path: assets/images/favorite.flr
24-
String get favorite => 'assets/images/favorite.flr';
27+
String get favorite =>
28+
'packages/example_resources/assets/images/favorite.flr';
2529

2630
/// File path: assets/images/flutter3.jpg
2731
AssetGenImage get flutter3 =>
@@ -35,8 +39,14 @@ class $AssetsImagesGen {
3539
RiveGenImage get skills => const RiveGenImage('assets/images/skills.riv');
3640

3741
/// List of all assets
38-
List<dynamic> get values =>
39-
[dart, favorite, flutter3, runningCarOnRoad, skills];
42+
List<dynamic> get values => [
43+
cat,
44+
dart,
45+
favorite,
46+
flutter3,
47+
runningCarOnRoad,
48+
skills,
49+
];
4050
}
4151

4252
class $AssetsUnknownGen {
@@ -51,7 +61,7 @@ class $AssetsUnknownGen {
5161
}
5262

5363
class ResAssets {
54-
ResAssets._();
64+
const ResAssets._();
5565

5666
static const String package = 'example_resources';
5767

@@ -132,11 +142,7 @@ class AssetGenImage {
132142
@Deprecated('Do not specify package for a generated library asset')
133143
String? package = package,
134144
}) {
135-
return AssetImage(
136-
_assetName,
137-
bundle: bundle,
138-
package: package,
139-
);
145+
return AssetImage(_assetName, bundle: bundle, package: package);
140146
}
141147

142148
String get path => _assetName;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ ${isPackage ? "\n static const String package = '$packageName';" : ''}
122122
bool get isConstConstructor => true;
123123

124124
bool isLottieFile(AssetType asset) {
125-
if (asset.extension == '.lottie') {
125+
if (asset.extension == '.lottie' || asset.extension == '.tgs') {
126126
return true;
127127
}
128128
if (!_supportedMimeTypes.contains(asset.mime)) {

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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ flutter:
1212
- assets/lottie/hamburger_arrow.json
1313
- assets/lottie/spinning_carrousel.zip
1414
- assets/lottie/XuiIZ9X1Rf.lottie
15+
- assets/lottie/cat_cat.tgs

0 commit comments

Comments
 (0)