Skip to content

Commit 341d1a3

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

File tree

10 files changed

+98
-123
lines changed

10 files changed

+98
-123
lines changed
25.4 KB
Binary file not shown.

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

Lines changed: 25 additions & 44 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;
@@ -313,17 +309,11 @@ class AssetGenImage {
313309
}
314310

315311
class SvgGenImage {
316-
const SvgGenImage(
317-
this._assetName, {
318-
this.size,
319-
this.flavors = const {},
320-
}) : _isVecFormat = false;
321-
322-
const SvgGenImage.vec(
323-
this._assetName, {
324-
this.size,
325-
this.flavors = const {},
326-
}) : _isVecFormat = true;
312+
const SvgGenImage(this._assetName, {this.size, this.flavors = const {}})
313+
: _isVecFormat = false;
314+
315+
const SvgGenImage.vec(this._assetName, {this.size, this.flavors = const {}})
316+
: _isVecFormat = true;
327317

328318
final String _assetName;
329319
final Size? size;
@@ -390,10 +380,7 @@ class SvgGenImage {
390380
}
391381

392382
class RiveGenImage {
393-
const RiveGenImage(
394-
this._assetName, {
395-
this.flavors = const {},
396-
});
383+
const RiveGenImage(this._assetName, {this.flavors = const {}});
397384

398385
final String _assetName;
399386
final Set<String> flavors;
@@ -431,10 +418,7 @@ class RiveGenImage {
431418
}
432419

433420
class LottieGenImage {
434-
const LottieGenImage(
435-
this._assetName, {
436-
this.flavors = const {},
437-
});
421+
const LottieGenImage(this._assetName, {this.flavors = const {}});
438422

439423
final String _assetName;
440424
final Set<String> flavors;
@@ -451,11 +435,8 @@ class LottieGenImage {
451435
_lottie.LottieImageProviderFactory? imageProviderFactory,
452436
Key? key,
453437
AssetBundle? bundle,
454-
Widget Function(
455-
BuildContext,
456-
Widget,
457-
_lottie.LottieComposition?,
458-
)? frameBuilder,
438+
Widget Function(BuildContext, Widget, _lottie.LottieComposition?)?
439+
frameBuilder,
459440
ImageErrorWidgetBuilder? errorBuilder,
460441
double? width,
461442
double? height,

examples/example/lib/gen/colors.gen.dart

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,19 @@ class MyColorName {
3939
/// 700: #FFC31F1F
4040
/// 800: #FFBD1919
4141
/// 900: #FFB20F0F
42-
static const MaterialColor crimsonRed = MaterialColor(
43-
0xFFCF2A2A,
44-
<int, Color>{
45-
50: Color(0xFFF9E5E5),
46-
100: Color(0xFFF1BFBF),
47-
200: Color(0xFFE79595),
48-
300: Color(0xFFDD6A6A),
49-
400: Color(0xFFD64A4A),
50-
500: Color(0xFFCF2A2A),
51-
600: Color(0xFFCA2525),
52-
700: Color(0xFFC31F1F),
53-
800: Color(0xFFBD1919),
54-
900: Color(0xFFB20F0F),
55-
},
56-
);
42+
static const MaterialColor crimsonRed =
43+
MaterialColor(0xFFCF2A2A, <int, Color>{
44+
50: Color(0xFFF9E5E5),
45+
100: Color(0xFFF1BFBF),
46+
200: Color(0xFFE79595),
47+
300: Color(0xFFDD6A6A),
48+
400: Color(0xFFD64A4A),
49+
500: Color(0xFFCF2A2A),
50+
600: Color(0xFFCA2525),
51+
700: Color(0xFFC31F1F),
52+
800: Color(0xFFBD1919),
53+
900: Color(0xFFB20F0F),
54+
});
5755

5856
/// Color: #979797
5957
static const Color gray410 = Color(0xFF979797);
@@ -75,34 +73,30 @@ class MyColorName {
7573
/// 700: #FFD7821D
7674
/// 800: #FFD27817
7775
/// 900: #FFCA670E
78-
static const MaterialColor yellowOcher = MaterialColor(
79-
0xFFDF9527,
80-
<int, Color>{
81-
50: Color(0xFFFBF2E5),
82-
100: Color(0xFFF5DFBE),
83-
200: Color(0xFFEFCA93),
84-
300: Color(0xFFE9B568),
85-
400: Color(0xFFE4A547),
86-
500: Color(0xFFDF9527),
87-
600: Color(0xFFDB8D23),
88-
700: Color(0xFFD7821D),
89-
800: Color(0xFFD27817),
90-
900: Color(0xFFCA670E),
91-
},
92-
);
76+
static const MaterialColor yellowOcher =
77+
MaterialColor(0xFFDF9527, <int, Color>{
78+
50: Color(0xFFFBF2E5),
79+
100: Color(0xFFF5DFBE),
80+
200: Color(0xFFEFCA93),
81+
300: Color(0xFFE9B568),
82+
400: Color(0xFFE4A547),
83+
500: Color(0xFFDF9527),
84+
600: Color(0xFFDB8D23),
85+
700: Color(0xFFD7821D),
86+
800: Color(0xFFD27817),
87+
900: Color(0xFFCA670E),
88+
});
9389

9490
/// MaterialAccentColor:
9591
/// 100: #FFFFE8E0
9692
/// 200: #FFFFBCA3
9793
/// 400: #FFFFA989
9894
/// 700: #FFFF9E7A
99-
static const MaterialAccentColor yellowOcherAccent = MaterialAccentColor(
100-
0xFFFFBCA3,
101-
<int, Color>{
102-
100: Color(0xFFFFE8E0),
103-
200: Color(0xFFFFBCA3),
104-
400: Color(0xFFFFA989),
105-
700: Color(0xFFFF9E7A),
106-
},
107-
);
95+
static const MaterialAccentColor yellowOcherAccent =
96+
MaterialAccentColor(0xFFFFBCA3, <int, Color>{
97+
100: Color(0xFFFFE8E0),
98+
200: Color(0xFFFFBCA3),
99+
400: Color(0xFFFFA989),
100+
700: Color(0xFFFF9E7A),
101+
});
108102
}

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: 25 additions & 38 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

@@ -60,11 +70,7 @@ class ResAssets {
6070
}
6171

6272
class AssetGenImage {
63-
const AssetGenImage(
64-
this._assetName, {
65-
this.size,
66-
this.flavors = const {},
67-
});
73+
const AssetGenImage(this._assetName, {this.size, this.flavors = const {}});
6874

6975
final String _assetName;
7076

@@ -132,11 +138,7 @@ class AssetGenImage {
132138
@Deprecated('Do not specify package for a generated library asset')
133139
String? package = package,
134140
}) {
135-
return AssetImage(
136-
_assetName,
137-
bundle: bundle,
138-
package: package,
139-
);
141+
return AssetImage(_assetName, bundle: bundle, package: package);
140142
}
141143

142144
String get path => _assetName;
@@ -145,17 +147,11 @@ class AssetGenImage {
145147
}
146148

147149
class SvgGenImage {
148-
const SvgGenImage(
149-
this._assetName, {
150-
this.size,
151-
this.flavors = const {},
152-
}) : _isVecFormat = false;
153-
154-
const SvgGenImage.vec(
155-
this._assetName, {
156-
this.size,
157-
this.flavors = const {},
158-
}) : _isVecFormat = true;
150+
const SvgGenImage(this._assetName, {this.size, this.flavors = const {}})
151+
: _isVecFormat = false;
152+
153+
const SvgGenImage.vec(this._assetName, {this.size, this.flavors = const {}})
154+
: _isVecFormat = true;
159155

160156
final String _assetName;
161157
final Size? size;
@@ -225,10 +221,7 @@ class SvgGenImage {
225221
}
226222

227223
class RiveGenImage {
228-
const RiveGenImage(
229-
this._assetName, {
230-
this.flavors = const {},
231-
});
224+
const RiveGenImage(this._assetName, {this.flavors = const {}});
232225

233226
final String _assetName;
234227
final Set<String> flavors;
@@ -268,10 +261,7 @@ class RiveGenImage {
268261
}
269262

270263
class LottieGenImage {
271-
const LottieGenImage(
272-
this._assetName, {
273-
this.flavors = const {},
274-
});
264+
const LottieGenImage(this._assetName, {this.flavors = const {}});
275265

276266
final String _assetName;
277267
final Set<String> flavors;
@@ -290,11 +280,8 @@ class LottieGenImage {
290280
_lottie.LottieImageProviderFactory? imageProviderFactory,
291281
Key? key,
292282
AssetBundle? bundle,
293-
Widget Function(
294-
BuildContext,
295-
Widget,
296-
_lottie.LottieComposition?,
297-
)? frameBuilder,
283+
Widget Function(BuildContext, Widget, _lottie.LottieComposition?)?
284+
frameBuilder,
298285
ImageErrorWidgetBuilder? errorBuilder,
299286
double? width,
300287
double? height,

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)) {

0 commit comments

Comments
 (0)