Skip to content

Add support Telegram Sticker .tgs in Lottie Integration #659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ Widget build(BuildContext context) {
|---------------------------------------------------------|----------------------|-----------------------|-------------------------------------------|
| [flutter_svg](https://pub.dev/packages/flutter_svg) | .svg | `flutter_svg: true` | Assets.images.icons.paint.**svg()** |
| [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()** |
| [lottie](https://pub.dev/packages/lottie) | .json, .zip, .lottie, .tgs | `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.
**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.

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

Expand Down
Binary file added examples/example/assets/lottie/cat.tgs
Binary file not shown.
4 changes: 4 additions & 0 deletions examples/example/lib/gen/assets.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class $AssetsLottieGen {
LottieGenImage get alarmClockLottieV440 =>
const LottieGenImage('assets/lottie/alarm-clock-lottie-v440.json');

/// File path: assets/lottie/cat.tgs
LottieGenImage get cat => const LottieGenImage('assets/lottie/cat.tgs');

/// File path: assets/lottie/geometrical-animation.json
LottieGenImage get geometricalAnimation =>
const LottieGenImage('assets/lottie/geometrical-animation.json');
Expand All @@ -101,6 +104,7 @@ class $AssetsLottieGen {
List<LottieGenImage> get values => [
xuiIZ9X1Rf,
alarmClockLottieV440,
cat,
geometricalAnimation,
hamburgerArrow,
spinningCarrousel,
Expand Down
8 changes: 8 additions & 0 deletions examples/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:example/gen/colors.gen.dart';
import 'package:example/gen/fonts.gen.dart';
import 'package:example_resources/gen/assets.gen.dart';
import 'package:flutter/material.dart';
import 'package:lottie/lottie.dart';

void main() {
print(MyAssets.images.chip4.chip4.flavors);
Expand Down Expand Up @@ -59,6 +60,13 @@ class MyApp extends StatelessWidget {
fit: BoxFit.contain,
),
),
SizedBox(
width: 200,
height: 200,
child: MyAssets.lottie.cat.lottie(
decoder: LottieComposition.decodeGZip,
),
),
MyAssets.images.chip1.image(),
Container(
height: 400,
Expand Down
Binary file not shown.
5 changes: 4 additions & 1 deletion examples/example_resources/lib/gen/assets.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import 'package:vector_graphics/vector_graphics.dart' as _vg;
class $AssetsImagesGen {
const $AssetsImagesGen();

/// File path: assets/images/cat.tgs
LottieGenImage get cat => const LottieGenImage('assets/images/cat.tgs');

/// File path: assets/images/dart.svg
SvgGenImage get dart => const SvgGenImage('assets/images/dart.svg');

Expand All @@ -36,7 +39,7 @@ class $AssetsImagesGen {

/// List of all assets
List<dynamic> get values =>
[dart, favorite, flutter3, runningCarOnRoad, skills];
[cat, dart, favorite, flutter3, runningCarOnRoad, skills];
}

class $AssetsUnknownGen {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ ${isPackage ? "\n static const String package = '$packageName';" : ''}
bool get isConstConstructor => true;

bool isLottieFile(AssetType asset) {
if (asset.extension == '.lottie') {
if (asset.extension == '.lottie' || asset.extension == '.tgs') {
return true;
}
if (!_supportedMimeTypes.contains(asset.mime)) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ flutter:
- assets/lottie/hamburger_arrow.json
- assets/lottie/spinning_carrousel.zip
- assets/lottie/XuiIZ9X1Rf.lottie
- assets/lottie/cat_cat.tgs