mirror of
https://github.com/xvrh/lottie-flutter.git
synced 2025-08-06 16:39:36 +08:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
8dcb052fe1 | |||
a333a42f01 |
15
CHANGELOG.md
15
CHANGELOG.md
@ -1,3 +1,18 @@
|
||||
|
||||
## [2.1.0]
|
||||
- Improve the cache to ensure that there is not an empty frame each time we load an animation.
|
||||
The method `AssetLottie('anim.json').load()` returns a `SynchronousFuture` if it has been loaded previously.
|
||||
- Expose the `LottieCache` singleton.
|
||||
It allows to change the cache behaviour and clear the entries.
|
||||
|
||||
```dart
|
||||
void main() {
|
||||
Lottie.cache.maximumSize = 10;
|
||||
Lottie.cache.clear();
|
||||
Lottie.cache.evict(NetworkLottie('https://lottie.com/anim.json'));
|
||||
}
|
||||
```
|
||||
|
||||
## [2.0.0]
|
||||
- **Breaking change**: the lottie widget will be smaller if it relies on the intrinsic size of the composition.
|
||||
|
||||
|
@ -23,7 +23,7 @@ import 'package:lottie/lottie.dart';
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -61,7 +61,7 @@ import 'package:lottie/lottie.dart';
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
State<MyApp> createState() => _MyAppState();
|
||||
@ -136,7 +136,7 @@ This example shows how to load and parse a Lottie composition from a json file.
|
||||
|
||||
```dart
|
||||
class MyWidget extends StatefulWidget {
|
||||
const MyWidget({Key? key}) : super(key: key);
|
||||
const MyWidget({super.key});
|
||||
|
||||
@override
|
||||
State<MyWidget> createState() => _MyWidgetState();
|
||||
@ -182,7 +182,7 @@ a specific position and size.
|
||||
class CustomDrawer extends StatelessWidget {
|
||||
final LottieComposition composition;
|
||||
|
||||
const CustomDrawer(this.composition, {Key? key}) : super(key: key);
|
||||
const CustomDrawer(this.composition, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -10,14 +10,16 @@ linter:
|
||||
always_declare_return_types: true
|
||||
avoid_dynamic_calls: true
|
||||
avoid_escaping_inner_quotes: true
|
||||
avoid_returning_null_for_future: true
|
||||
avoid_setters_without_getters: true
|
||||
cancel_subscriptions: true
|
||||
cast_nullable_to_non_nullable: true
|
||||
close_sinks: true
|
||||
no_adjacent_strings_in_list: true
|
||||
no_default_cases: true
|
||||
omit_local_variable_types: true
|
||||
only_throw_errors: true
|
||||
prefer_interpolation_to_compose_strings: true
|
||||
prefer_relative_imports: true
|
||||
prefer_single_quotes: true
|
||||
sort_child_properties_last: true
|
||||
sort_pub_dependencies: true
|
||||
@ -27,3 +29,4 @@ linter:
|
||||
unnecessary_statements: true
|
||||
unsafe_html: true
|
||||
use_raw_strings: true
|
||||
use_super_parameters: true
|
||||
|
@ -9,7 +9,7 @@ import 'package:lottie/lottie.dart';
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -5,7 +5,7 @@ import 'package:lottie/lottie.dart';
|
||||
void main() => runApp(const App());
|
||||
|
||||
class App extends StatelessWidget {
|
||||
const App({Key? key}) : super(key: key);
|
||||
const App({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -6,7 +6,7 @@ void main() async {
|
||||
}
|
||||
|
||||
class App extends StatelessWidget {
|
||||
const App({Key? key}) : super(key: key);
|
||||
const App({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -4,7 +4,7 @@ import 'package:lottie/lottie.dart';
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
State<MyApp> createState() => _MyAppState();
|
||||
|
@ -12,7 +12,7 @@ import 'package:lottie/lottie.dart';
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
State<MyApp> createState() => _MyAppState();
|
||||
|
@ -4,7 +4,7 @@ import 'package:lottie/lottie.dart';
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
59
example/lib/examples/cache.dart
Normal file
59
example/lib/examples/cache.dart
Normal file
@ -0,0 +1,59 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lottie/lottie.dart';
|
||||
|
||||
void main() => runApp(const App());
|
||||
|
||||
class App extends StatelessWidget {
|
||||
const App({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(body: _Page()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Page extends StatefulWidget {
|
||||
@override
|
||||
__PageState createState() => __PageState();
|
||||
}
|
||||
|
||||
class __PageState extends State<_Page> {
|
||||
var _animationKey = UniqueKey();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Lottie.network(
|
||||
'https://assets10.lottiefiles.com/datafiles/QeC7XD39x4C1CIj/data.json',
|
||||
key: _animationKey,
|
||||
fit: BoxFit.contain,
|
||||
width: 200,
|
||||
height: 200,
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Lottie.cache.clear();
|
||||
Lottie.cache.maximumSize = 10;
|
||||
},
|
||||
child: const Text('Clear cache'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_animationKey = UniqueKey();
|
||||
});
|
||||
},
|
||||
child: const Text('Recreate animation'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ import 'package:lottie/lottie.dart';
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -18,7 +18,7 @@ class MyApp extends StatelessWidget {
|
||||
}
|
||||
|
||||
class MyWidget extends StatefulWidget {
|
||||
const MyWidget({Key? key}) : super(key: key);
|
||||
const MyWidget({super.key});
|
||||
|
||||
@override
|
||||
State<MyWidget> createState() => _MyWidgetState();
|
||||
@ -60,7 +60,7 @@ class _MyWidgetState extends State<MyWidget> {
|
||||
class CustomDrawer extends StatelessWidget {
|
||||
final LottieComposition composition;
|
||||
|
||||
const CustomDrawer(this.composition, {Key? key}) : super(key: key);
|
||||
const CustomDrawer(this.composition, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -5,7 +5,7 @@ import 'package:lottie/lottie.dart';
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -19,7 +19,7 @@ class MyApp extends StatelessWidget {
|
||||
|
||||
//--- example
|
||||
class MyWidget extends StatefulWidget {
|
||||
const MyWidget({Key? key}) : super(key: key);
|
||||
const MyWidget({super.key});
|
||||
|
||||
@override
|
||||
State<MyWidget> createState() => _MyWidgetState();
|
||||
|
@ -4,7 +4,7 @@ import 'package:lottie/lottie.dart';
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -7,7 +7,7 @@ void main() async {
|
||||
}
|
||||
|
||||
class App extends StatefulWidget {
|
||||
const App({Key? key}) : super(key: key);
|
||||
const App({super.key});
|
||||
|
||||
@override
|
||||
State<App> createState() => _AppState();
|
||||
|
@ -7,7 +7,7 @@ void main() async {
|
||||
}
|
||||
|
||||
class App extends StatefulWidget {
|
||||
const App({Key? key}) : super(key: key);
|
||||
const App({super.key});
|
||||
|
||||
@override
|
||||
State<App> createState() => _AppState();
|
||||
|
@ -4,7 +4,7 @@ import 'package:lottie/lottie.dart';
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -4,7 +4,7 @@ import 'package:lottie/lottie.dart';
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -6,7 +6,7 @@ void main() async {
|
||||
}
|
||||
|
||||
class App extends StatefulWidget {
|
||||
const App({Key? key}) : super(key: key);
|
||||
const App({super.key});
|
||||
|
||||
@override
|
||||
State<App> createState() => _AppState();
|
||||
|
@ -9,7 +9,7 @@ void main() async {
|
||||
}
|
||||
|
||||
class App extends StatefulWidget {
|
||||
const App({Key? key}) : super(key: key);
|
||||
const App({super.key});
|
||||
|
||||
@override
|
||||
State<App> createState() => _AppState();
|
||||
@ -48,7 +48,7 @@ class _AppState extends State<App> with TickerProviderStateMixin {
|
||||
class _LottieDetails extends StatefulWidget {
|
||||
final LottieComposition composition;
|
||||
|
||||
const _LottieDetails(this.composition, {Key? key}) : super(key: key);
|
||||
const _LottieDetails(this.composition);
|
||||
|
||||
@override
|
||||
_LottieDetailsState createState() => _LottieDetailsState();
|
||||
|
@ -4,7 +4,7 @@ import 'package:lottie/lottie.dart';
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
State<MyApp> createState() => _MyAppState();
|
||||
|
@ -12,7 +12,7 @@ void main() async {
|
||||
}
|
||||
|
||||
class App extends StatefulWidget {
|
||||
const App({Key? key}) : super(key: key);
|
||||
const App({super.key});
|
||||
|
||||
@override
|
||||
State<App> createState() => _AppState();
|
||||
|
@ -10,7 +10,7 @@ import 'package:path_provider/path_provider.dart';
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
State<MyApp> createState() => _MyAppState();
|
||||
|
@ -4,7 +4,7 @@ import 'package:lottie/lottie.dart';
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -4,7 +4,7 @@ import 'package:lottie/lottie.dart';
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -14,7 +14,7 @@ void main() {
|
||||
}
|
||||
|
||||
class App extends StatelessWidget {
|
||||
const App({Key? key}) : super(key: key);
|
||||
const App({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -64,7 +64,7 @@ class App extends StatelessWidget {
|
||||
class _Item extends StatelessWidget {
|
||||
final Widget child;
|
||||
|
||||
const _Item({Key? key, required this.child}) : super(key: key);
|
||||
const _Item({required this.child});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -89,7 +89,7 @@ class _Item extends StatelessWidget {
|
||||
class Detail extends StatefulWidget {
|
||||
final String assetName;
|
||||
|
||||
const Detail(this.assetName, {Key? key}) : super(key: key);
|
||||
const Detail(this.assetName, {super.key});
|
||||
|
||||
@override
|
||||
State<Detail> createState() => _DetailState();
|
||||
|
@ -13,7 +13,7 @@ void main() async {
|
||||
class App extends StatelessWidget {
|
||||
final LottieComposition composition;
|
||||
|
||||
const App({Key? key, required this.composition}) : super(key: key);
|
||||
const App({super.key, required this.composition});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -103,8 +103,7 @@ class _Lottie extends StatefulWidget {
|
||||
final AlignmentGeometry? alignment;
|
||||
|
||||
const _Lottie(this.composition,
|
||||
{Key? key, this.width, this.height, this.fit, this.alignment})
|
||||
: super(key: key);
|
||||
{this.width, this.height, this.fit, this.alignment});
|
||||
|
||||
@override
|
||||
__LottieState createState() => __LottieState();
|
||||
|
@ -6,7 +6,7 @@ void main() async {
|
||||
}
|
||||
|
||||
class App extends StatelessWidget {
|
||||
const App({Key? key}) : super(key: key);
|
||||
const App({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -6,7 +6,7 @@ void main() async {
|
||||
}
|
||||
|
||||
class App extends StatelessWidget {
|
||||
const App({Key? key}) : super(key: key);
|
||||
const App({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -7,7 +7,7 @@ packages:
|
||||
name: archive
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.3.2"
|
||||
version: "3.3.5"
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -43,6 +43,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.16.0"
|
||||
convert:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: convert
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.1.1"
|
||||
crypto:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -101,7 +108,7 @@ packages:
|
||||
name: golden_toolkit
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.13.0"
|
||||
version: "0.14.0"
|
||||
http:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -116,6 +123,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.2"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: js
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.5"
|
||||
lints:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -136,7 +150,7 @@ packages:
|
||||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "2.0.0"
|
||||
version: "2.1.0"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -178,7 +192,7 @@ packages:
|
||||
name: path_provider_android
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.21"
|
||||
version: "2.0.22"
|
||||
path_provider_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -228,6 +242,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.3"
|
||||
pointycastle:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pointycastle
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.6.2"
|
||||
process:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -302,7 +323,7 @@ packages:
|
||||
name: win32
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
version: "3.1.2"
|
||||
xdg_directories:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -311,5 +332,5 @@ packages:
|
||||
source: hosted
|
||||
version: "0.2.0+2"
|
||||
sdks:
|
||||
dart: ">=2.18.0 <3.0.0"
|
||||
dart: ">=2.18.4 <3.0.0"
|
||||
flutter: ">=3.3.0"
|
||||
|
@ -10,7 +10,7 @@ export 'src/options.dart' show LottieOptions;
|
||||
export 'src/providers/asset_provider.dart' show AssetLottie;
|
||||
export 'src/providers/file_provider.dart' show FileLottie;
|
||||
export 'src/providers/load_image.dart' show LottieImageProviderFactory;
|
||||
export 'src/providers/lottie_provider.dart' show LottieProvider;
|
||||
export 'src/providers/lottie_provider.dart' show LottieProvider, LottieCache;
|
||||
export 'src/providers/memory_provider.dart' show MemoryLottie;
|
||||
export 'src/providers/network_provider.dart' show NetworkLottie;
|
||||
export 'src/raw_lottie.dart' show RawLottie;
|
||||
|
@ -4,7 +4,7 @@ import '../../value/keyframe.dart';
|
||||
import 'keyframe_animation.dart';
|
||||
|
||||
class ColorKeyframeAnimation extends KeyframeAnimation<Color> {
|
||||
ColorKeyframeAnimation(List<Keyframe<Color>> keyframes) : super(keyframes);
|
||||
ColorKeyframeAnimation(super.keyframes);
|
||||
|
||||
@override
|
||||
Color getValue(Keyframe<Color> keyframe, double keyframeProgress) {
|
||||
|
@ -3,7 +3,7 @@ import '../../value/keyframe.dart';
|
||||
import 'keyframe_animation.dart';
|
||||
|
||||
class DoubleKeyframeAnimation extends KeyframeAnimation<double> {
|
||||
DoubleKeyframeAnimation(List<Keyframe<double>> keyframes) : super(keyframes);
|
||||
DoubleKeyframeAnimation(super.keyframes);
|
||||
|
||||
@override
|
||||
double getValue(Keyframe<double> keyframe, double keyframeProgress) {
|
||||
|
@ -3,7 +3,7 @@ import '../../value/keyframe.dart';
|
||||
import 'keyframe_animation.dart';
|
||||
|
||||
class IntegerKeyframeAnimation extends KeyframeAnimation<int> {
|
||||
IntegerKeyframeAnimation(List<Keyframe<int>> keyframes) : super(keyframes);
|
||||
IntegerKeyframeAnimation(super.keyframes);
|
||||
|
||||
@override
|
||||
int getValue(Keyframe<int> keyframe, double keyframeProgress) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import '../../value/keyframe.dart';
|
||||
import 'base_keyframe_animation.dart';
|
||||
|
||||
abstract class KeyframeAnimation<T extends Object>
|
||||
extends BaseKeyframeAnimation<T, T> {
|
||||
KeyframeAnimation(List<Keyframe<T>> keyframes) : super(keyframes);
|
||||
KeyframeAnimation(super.keyframes);
|
||||
}
|
||||
|
@ -7,9 +7,9 @@ class PathKeyframe extends Keyframe<Offset> {
|
||||
Path? _path;
|
||||
final Keyframe<Offset> _pointKeyFrame;
|
||||
|
||||
PathKeyframe(LottieComposition composition, Keyframe<Offset> keyframe)
|
||||
PathKeyframe(LottieComposition super.composition, Keyframe<Offset> keyframe)
|
||||
: _pointKeyFrame = keyframe,
|
||||
super(composition,
|
||||
super(
|
||||
startValue: keyframe.startValue,
|
||||
endValue: keyframe.endValue,
|
||||
interpolator: keyframe.interpolator,
|
||||
|
@ -7,7 +7,7 @@ class PathKeyframeAnimation extends KeyframeAnimation<Offset> {
|
||||
PathKeyframe? _pathMeasureKeyframe;
|
||||
late PathMetric _pathMeasure;
|
||||
|
||||
PathKeyframeAnimation(List<Keyframe<Offset>> keyframes) : super(keyframes);
|
||||
PathKeyframeAnimation(super.keyframes);
|
||||
|
||||
@override
|
||||
Offset getValue(Keyframe<Offset> keyframe, double keyframeProgress) {
|
||||
|
@ -3,7 +3,7 @@ import '../../value/keyframe.dart';
|
||||
import 'keyframe_animation.dart';
|
||||
|
||||
class PointKeyframeAnimation extends KeyframeAnimation<Offset> {
|
||||
PointKeyframeAnimation(List<Keyframe<Offset>> keyframes) : super(keyframes);
|
||||
PointKeyframeAnimation(super.keyframes);
|
||||
|
||||
@override
|
||||
Offset getValue(Keyframe<Offset> keyframe, double keyframeProgress) {
|
||||
|
@ -11,8 +11,7 @@ class ShapeKeyframeAnimation extends BaseKeyframeAnimation<ShapeData, Path> {
|
||||
final Path _tempPath = PathFactory.create();
|
||||
List<ShapeModifierContent>? _shapeModifiers;
|
||||
|
||||
ShapeKeyframeAnimation(List<Keyframe<ShapeData>> keyframes)
|
||||
: super(keyframes);
|
||||
ShapeKeyframeAnimation(super.keyframes);
|
||||
|
||||
@override
|
||||
Path getValue(Keyframe<ShapeData> keyframe, double keyframeProgress) {
|
||||
|
@ -5,8 +5,7 @@ import '../../value/lottie_value_callback.dart';
|
||||
import 'keyframe_animation.dart';
|
||||
|
||||
class TextKeyframeAnimation extends KeyframeAnimation<DocumentData> {
|
||||
TextKeyframeAnimation(List<Keyframe<DocumentData>> keyframes)
|
||||
: super(keyframes);
|
||||
TextKeyframeAnimation(super.keyframes);
|
||||
|
||||
@override
|
||||
DocumentData getValue(
|
||||
|
@ -4,6 +4,7 @@ import '../lottie.dart';
|
||||
import 'composition.dart';
|
||||
import 'l.dart';
|
||||
import 'lottie_builder.dart';
|
||||
import 'providers/lottie_provider.dart';
|
||||
|
||||
/// A widget to display a loaded [LottieComposition].
|
||||
/// The [controller] property allows to specify a custom AnimationController that
|
||||
@ -11,8 +12,11 @@ import 'lottie_builder.dart';
|
||||
/// automatically and the behavior could be adjusted with the properties [animate],
|
||||
/// [repeat] and [reverse].
|
||||
class Lottie extends StatefulWidget {
|
||||
/// The cache instance for recently loaded Lottie compositions.
|
||||
static LottieCache get cache => sharedLottieCache;
|
||||
|
||||
const Lottie({
|
||||
Key? key,
|
||||
super.key,
|
||||
required this.composition,
|
||||
this.controller,
|
||||
this.width,
|
||||
@ -30,8 +34,7 @@ class Lottie extends StatefulWidget {
|
||||
}) : animate = animate ?? true,
|
||||
reverse = reverse ?? false,
|
||||
repeat = repeat ?? true,
|
||||
addRepaintBoundary = addRepaintBoundary ?? true,
|
||||
super(key: key);
|
||||
addRepaintBoundary = addRepaintBoundary ?? true;
|
||||
|
||||
/// Creates a widget that displays an [LottieComposition] obtained from an [AssetBundle].
|
||||
static LottieBuilder asset(
|
||||
|
@ -41,7 +41,7 @@ typedef LottieErrorWidgetBuilder = Widget Function(
|
||||
///
|
||||
class LottieBuilder extends StatefulWidget {
|
||||
const LottieBuilder({
|
||||
Key? key,
|
||||
super.key,
|
||||
required this.lottie,
|
||||
this.controller,
|
||||
this.frameRate,
|
||||
@ -60,7 +60,7 @@ class LottieBuilder extends StatefulWidget {
|
||||
this.addRepaintBoundary,
|
||||
this.filterQuality,
|
||||
this.onWarning,
|
||||
}) : super(key: key);
|
||||
});
|
||||
|
||||
/// Creates a widget that displays an [LottieComposition] obtained from the network.
|
||||
LottieBuilder.network(
|
||||
@ -75,7 +75,7 @@ class LottieBuilder extends StatefulWidget {
|
||||
this.options,
|
||||
LottieImageProviderFactory? imageProviderFactory,
|
||||
this.onLoaded,
|
||||
Key? key,
|
||||
super.key,
|
||||
this.frameBuilder,
|
||||
this.errorBuilder,
|
||||
this.width,
|
||||
@ -85,9 +85,8 @@ class LottieBuilder extends StatefulWidget {
|
||||
this.addRepaintBoundary,
|
||||
this.filterQuality,
|
||||
this.onWarning,
|
||||
}) : lottie = NetworkLottie(src,
|
||||
headers: headers, imageProviderFactory: imageProviderFactory),
|
||||
super(key: key);
|
||||
}) : lottie = NetworkLottie(src,
|
||||
headers: headers, imageProviderFactory: imageProviderFactory);
|
||||
|
||||
/// Creates a widget that displays an [LottieComposition] obtained from a [File].
|
||||
///
|
||||
@ -110,7 +109,7 @@ class LottieBuilder extends StatefulWidget {
|
||||
this.options,
|
||||
LottieImageProviderFactory? imageProviderFactory,
|
||||
this.onLoaded,
|
||||
Key? key,
|
||||
super.key,
|
||||
this.frameBuilder,
|
||||
this.errorBuilder,
|
||||
this.width,
|
||||
@ -120,8 +119,7 @@ class LottieBuilder extends StatefulWidget {
|
||||
this.addRepaintBoundary,
|
||||
this.filterQuality,
|
||||
this.onWarning,
|
||||
}) : lottie = FileLottie(file, imageProviderFactory: imageProviderFactory),
|
||||
super(key: key);
|
||||
}) : lottie = FileLottie(file, imageProviderFactory: imageProviderFactory);
|
||||
|
||||
/// Creates a widget that displays an [LottieComposition] obtained from an [AssetBundle].
|
||||
LottieBuilder.asset(
|
||||
@ -135,7 +133,7 @@ class LottieBuilder extends StatefulWidget {
|
||||
this.options,
|
||||
LottieImageProviderFactory? imageProviderFactory,
|
||||
this.onLoaded,
|
||||
Key? key,
|
||||
super.key,
|
||||
AssetBundle? bundle,
|
||||
this.frameBuilder,
|
||||
this.errorBuilder,
|
||||
@ -147,11 +145,10 @@ class LottieBuilder extends StatefulWidget {
|
||||
this.addRepaintBoundary,
|
||||
this.filterQuality,
|
||||
this.onWarning,
|
||||
}) : lottie = AssetLottie(name,
|
||||
}) : lottie = AssetLottie(name,
|
||||
bundle: bundle,
|
||||
package: package,
|
||||
imageProviderFactory: imageProviderFactory),
|
||||
super(key: key);
|
||||
imageProviderFactory: imageProviderFactory);
|
||||
|
||||
/// Creates a widget that displays an [LottieComposition] obtained from a [Uint8List].
|
||||
LottieBuilder.memory(
|
||||
@ -166,7 +163,7 @@ class LottieBuilder extends StatefulWidget {
|
||||
LottieImageProviderFactory? imageProviderFactory,
|
||||
this.onLoaded,
|
||||
this.errorBuilder,
|
||||
Key? key,
|
||||
super.key,
|
||||
this.frameBuilder,
|
||||
this.width,
|
||||
this.height,
|
||||
@ -175,9 +172,7 @@ class LottieBuilder extends StatefulWidget {
|
||||
this.addRepaintBoundary,
|
||||
this.filterQuality,
|
||||
this.onWarning,
|
||||
}) : lottie =
|
||||
MemoryLottie(bytes, imageProviderFactory: imageProviderFactory),
|
||||
super(key: key);
|
||||
}) : lottie = MemoryLottie(bytes, imageProviderFactory: imageProviderFactory);
|
||||
|
||||
/// The lottie animation to load.
|
||||
/// Example of providers: [AssetLottie], [NetworkLottie], [FileLottie], [MemoryLottie]
|
||||
|
@ -1,11 +1,9 @@
|
||||
import 'dart:ui';
|
||||
import '../../animation/keyframe/color_keyframe_animation.dart';
|
||||
import '../../value/keyframe.dart';
|
||||
import 'base_animatable_value.dart';
|
||||
|
||||
class AnimatableColorValue extends BaseAnimatableValue<Color, Color> {
|
||||
AnimatableColorValue.fromKeyframes(List<Keyframe<Color>> keyframes)
|
||||
: super.fromKeyframes(keyframes);
|
||||
AnimatableColorValue.fromKeyframes(super.keyframes) : super.fromKeyframes();
|
||||
|
||||
@override
|
||||
ColorKeyframeAnimation createAnimation() {
|
||||
|
@ -1,12 +1,10 @@
|
||||
import '../../animation/keyframe/double_keyframe_animation.dart';
|
||||
import '../../value/keyframe.dart';
|
||||
import 'base_animatable_value.dart';
|
||||
|
||||
class AnimatableDoubleValue extends BaseAnimatableValue<double, double> {
|
||||
AnimatableDoubleValue() : super.fromValue(0.0);
|
||||
|
||||
AnimatableDoubleValue.fromKeyframes(List<Keyframe<double>> keyframes)
|
||||
: super.fromKeyframes(keyframes);
|
||||
AnimatableDoubleValue.fromKeyframes(super.keyframes) : super.fromKeyframes();
|
||||
|
||||
@override
|
||||
DoubleKeyframeAnimation createAnimation() {
|
||||
|
@ -1,13 +1,11 @@
|
||||
import '../../animation/keyframe/gradient_color_keyframe_animation.dart';
|
||||
import '../../value/keyframe.dart';
|
||||
import '../content/gradient_color.dart';
|
||||
import 'base_animatable_value.dart';
|
||||
|
||||
class AnimatableGradientColorValue
|
||||
extends BaseAnimatableValue<GradientColor, GradientColor> {
|
||||
AnimatableGradientColorValue.fromKeyframes(
|
||||
List<Keyframe<GradientColor>> keyframes)
|
||||
: super.fromKeyframes(keyframes);
|
||||
AnimatableGradientColorValue.fromKeyframes(super.keyframes)
|
||||
: super.fromKeyframes();
|
||||
|
||||
@override
|
||||
GradientColorKeyframeAnimation createAnimation() {
|
||||
|
@ -1,13 +1,11 @@
|
||||
import '../../animation/keyframe/base_keyframe_animation.dart';
|
||||
import '../../animation/keyframe/integer_keyframe_animation.dart';
|
||||
import '../../value/keyframe.dart';
|
||||
import 'base_animatable_value.dart';
|
||||
|
||||
class AnimatableIntegerValue extends BaseAnimatableValue<int, int> {
|
||||
AnimatableIntegerValue() : super.fromValue(100);
|
||||
|
||||
AnimatableIntegerValue.fromKeyframes(List<Keyframe<int>> keyframes)
|
||||
: super.fromKeyframes(keyframes);
|
||||
AnimatableIntegerValue.fromKeyframes(super.keyframes) : super.fromKeyframes();
|
||||
|
||||
@override
|
||||
BaseKeyframeAnimation<int, int> createAnimation() {
|
||||
|
@ -1,11 +1,9 @@
|
||||
import 'dart:ui';
|
||||
import '../../animation/keyframe/point_keyframe_animation.dart';
|
||||
import '../../value/keyframe.dart';
|
||||
import 'base_animatable_value.dart';
|
||||
|
||||
class AnimatablePointValue extends BaseAnimatableValue<Offset, Offset> {
|
||||
AnimatablePointValue.fromKeyframes(List<Keyframe<Offset>> keyframes)
|
||||
: super.fromKeyframes(keyframes);
|
||||
AnimatablePointValue.fromKeyframes(super.keyframes) : super.fromKeyframes();
|
||||
|
||||
@override
|
||||
PointKeyframeAnimation createAnimation() {
|
||||
|
@ -1,16 +1,14 @@
|
||||
import 'dart:ui';
|
||||
import '../../animation/keyframe/base_keyframe_animation.dart';
|
||||
import '../../animation/keyframe/point_keyframe_animation.dart';
|
||||
import '../../value/keyframe.dart';
|
||||
import 'base_animatable_value.dart';
|
||||
|
||||
class AnimatableScaleValue extends BaseAnimatableValue<Offset, Offset> {
|
||||
AnimatableScaleValue.one() : this(const Offset(1, 1));
|
||||
|
||||
AnimatableScaleValue(Offset value) : super.fromValue(value);
|
||||
AnimatableScaleValue(super.value) : super.fromValue();
|
||||
|
||||
AnimatableScaleValue.fromKeyframes(List<Keyframe<Offset>> keyframes)
|
||||
: super.fromKeyframes(keyframes);
|
||||
AnimatableScaleValue.fromKeyframes(super.keyframes) : super.fromKeyframes();
|
||||
|
||||
@override
|
||||
BaseKeyframeAnimation<Offset, Offset> createAnimation() {
|
||||
|
@ -1,12 +1,10 @@
|
||||
import 'dart:ui';
|
||||
import '../../animation/keyframe/shape_keyframe_animation.dart';
|
||||
import '../../value/keyframe.dart';
|
||||
import '../content/shape_data.dart';
|
||||
import 'base_animatable_value.dart';
|
||||
|
||||
class AnimatableShapeValue extends BaseAnimatableValue<ShapeData, Path> {
|
||||
AnimatableShapeValue.fromKeyframes(List<Keyframe<ShapeData>> keyframes)
|
||||
: super.fromKeyframes(keyframes);
|
||||
AnimatableShapeValue.fromKeyframes(super.keyframes) : super.fromKeyframes();
|
||||
|
||||
@override
|
||||
ShapeKeyframeAnimation createAnimation() {
|
||||
|
@ -1,12 +1,10 @@
|
||||
import '../../animation/keyframe/text_keyframe_animation.dart';
|
||||
import '../../value/keyframe.dart';
|
||||
import '../document_data.dart';
|
||||
import 'base_animatable_value.dart';
|
||||
|
||||
class AnimatableTextFrame
|
||||
extends BaseAnimatableValue<DocumentData, DocumentData> {
|
||||
AnimatableTextFrame.fromKeyframes(List<Keyframe<DocumentData>> keyframes)
|
||||
: super.fromKeyframes(keyframes);
|
||||
AnimatableTextFrame.fromKeyframes(super.keyframes) : super.fromKeyframes();
|
||||
|
||||
@override
|
||||
TextKeyframeAnimation createAnimation() {
|
||||
|
@ -2,19 +2,16 @@ import 'dart:ui';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
import '../../animation/keyframe/base_keyframe_animation.dart';
|
||||
import '../../animation/keyframe/value_callback_keyframe_animation.dart';
|
||||
import '../../lottie_drawable.dart';
|
||||
import '../../lottie_property.dart';
|
||||
import '../../utils.dart';
|
||||
import '../../value/lottie_value_callback.dart';
|
||||
import 'base_layer.dart';
|
||||
import 'layer.dart';
|
||||
|
||||
class ImageLayer extends BaseLayer {
|
||||
final Paint paint = Paint();
|
||||
BaseKeyframeAnimation<ColorFilter, ColorFilter?>? _colorFilterAnimation;
|
||||
|
||||
ImageLayer(LottieDrawable lottieDrawable, Layer layerModel)
|
||||
: super(lottieDrawable, layerModel);
|
||||
ImageLayer(super.lottieDrawable, super.layerModel);
|
||||
|
||||
@override
|
||||
void drawLayer(Canvas canvas, Size size, Matrix4 parentMatrix,
|
||||
|
@ -1,12 +1,9 @@
|
||||
import 'dart:ui';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
import '../../lottie_drawable.dart';
|
||||
import 'base_layer.dart';
|
||||
import 'layer.dart';
|
||||
|
||||
class NullLayer extends BaseLayer {
|
||||
NullLayer(LottieDrawable lottieDrawable, Layer layerModel)
|
||||
: super(lottieDrawable, layerModel);
|
||||
NullLayer(super.lottieDrawable, super.layerModel);
|
||||
|
||||
@override
|
||||
void drawLayer(Canvas canvas, Size size, Matrix4 parentMatrix,
|
||||
|
@ -13,8 +13,8 @@ class AssetLottie extends LottieProvider {
|
||||
this.assetName, {
|
||||
this.bundle,
|
||||
this.package,
|
||||
LottieImageProviderFactory? imageProviderFactory,
|
||||
}) : super(imageProviderFactory: imageProviderFactory);
|
||||
super.imageProviderFactory,
|
||||
});
|
||||
|
||||
final String assetName;
|
||||
String get keyName =>
|
||||
@ -25,9 +25,8 @@ class AssetLottie extends LottieProvider {
|
||||
final String? package;
|
||||
|
||||
@override
|
||||
Future<LottieComposition> load() async {
|
||||
var cacheKey = 'asset-$keyName-$bundle';
|
||||
return sharedLottieCache.putIfAbsent(cacheKey, () async {
|
||||
Future<LottieComposition> load() {
|
||||
return sharedLottieCache.putIfAbsent(this, () async {
|
||||
final chosenBundle = bundle ?? rootBundle;
|
||||
|
||||
var data = await chosenBundle.load(keyName);
|
||||
|
@ -7,15 +7,13 @@ import 'lottie_provider.dart';
|
||||
import 'provider_io.dart' if (dart.library.html) 'provider_web.dart' as io;
|
||||
|
||||
class FileLottie extends LottieProvider {
|
||||
FileLottie(this.file, {LottieImageProviderFactory? imageProviderFactory})
|
||||
: super(imageProviderFactory: imageProviderFactory);
|
||||
FileLottie(this.file, {super.imageProviderFactory});
|
||||
|
||||
final Object /*io.File|html.File*/ file;
|
||||
|
||||
@override
|
||||
Future<LottieComposition> load() async {
|
||||
var cacheKey = 'file-${io.filePath(file)}';
|
||||
return sharedLottieCache.putIfAbsent(cacheKey, () async {
|
||||
Future<LottieComposition> load() {
|
||||
return sharedLottieCache.putIfAbsent(this, () async {
|
||||
var bytes = await io.loadFile(file);
|
||||
var composition = await LottieComposition.fromBytes(bytes,
|
||||
name: p.basenameWithoutExtension(io.filePath(file)),
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../../lottie.dart';
|
||||
import 'load_image.dart';
|
||||
|
||||
@ -19,37 +20,103 @@ abstract class LottieProvider {
|
||||
}
|
||||
|
||||
class LottieCache {
|
||||
final int maximumSize;
|
||||
final _cache = <String, Future<LottieComposition>>{};
|
||||
final Map<Object, Future<LottieComposition>> _pending =
|
||||
<Object, Future<LottieComposition>>{};
|
||||
final Map<Object, LottieComposition> _cache = <Object, LottieComposition>{};
|
||||
|
||||
LottieCache({int? maximumSize}) : maximumSize = maximumSize ?? 1000;
|
||||
/// Maximum number of entries to store in the cache.
|
||||
///
|
||||
/// Once this many entries have been cached, the least-recently-used entry is
|
||||
/// evicted when adding a new entry.
|
||||
int get maximumSize => _maximumSize;
|
||||
int _maximumSize = 1000;
|
||||
|
||||
Future<LottieComposition> putIfAbsent(
|
||||
String key, Future<LottieComposition> Function() load) {
|
||||
var composition = _cache[key];
|
||||
if (composition != null) {
|
||||
// Remove it so that we add it in front of the cache to prevent evicted
|
||||
_cache.remove(key);
|
||||
/// Changes the maximum cache size.
|
||||
///
|
||||
/// If the new size is smaller than the current number of elements, the
|
||||
/// extraneous elements are evicted immediately. Setting this to zero and then
|
||||
/// returning it to its original value will therefore immediately clear the
|
||||
/// cache.
|
||||
set maximumSize(int value) {
|
||||
assert(value >= 0);
|
||||
if (value == maximumSize) {
|
||||
return;
|
||||
}
|
||||
_maximumSize = value;
|
||||
if (maximumSize == 0) {
|
||||
clear();
|
||||
} else {
|
||||
composition = load();
|
||||
}
|
||||
|
||||
_cache[key] = composition;
|
||||
|
||||
_checkCacheSize();
|
||||
|
||||
return composition;
|
||||
}
|
||||
|
||||
void _checkCacheSize() {
|
||||
while (_cache.length > maximumSize) {
|
||||
_cache.remove(_cache.keys.first);
|
||||
while (_cache.length > maximumSize) {
|
||||
_cache.remove(_cache.keys.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Evicts all entries from the cache.
|
||||
///
|
||||
/// This is useful if, for instance, the root asset bundle has been updated
|
||||
/// and therefore new images must be obtained.
|
||||
void clear() {
|
||||
_cache.clear();
|
||||
}
|
||||
|
||||
/// Evicts a single entry from the cache, returning true if successful.
|
||||
bool evict(Object key) {
|
||||
return _cache.remove(key) != null;
|
||||
}
|
||||
|
||||
/// Returns the previously cached [LottieComposition] for the given key, if available;
|
||||
/// if not, calls the given callback to obtain it first. In either case, the
|
||||
/// key is moved to the "most recently used" position.
|
||||
///
|
||||
/// The arguments must not be null. The `loader` cannot return null.
|
||||
Future<LottieComposition> putIfAbsent(
|
||||
Object key,
|
||||
Future<LottieComposition> Function() loader,
|
||||
) {
|
||||
var pendingResult = _pending[key];
|
||||
if (pendingResult != null) {
|
||||
return pendingResult;
|
||||
}
|
||||
|
||||
var result = _cache[key];
|
||||
if (result != null) {
|
||||
// Remove the provider from the list so that we can put it back in below
|
||||
// and thus move it to the end of the list.
|
||||
_cache.remove(key);
|
||||
} else {
|
||||
if (_cache.length == maximumSize && maximumSize > 0) {
|
||||
_cache.remove(_cache.keys.first);
|
||||
}
|
||||
pendingResult = loader();
|
||||
_pending[key] = pendingResult;
|
||||
pendingResult.then<void>((LottieComposition data) {
|
||||
_pending.remove(key);
|
||||
_add(key, data);
|
||||
|
||||
result = data; // in case it was a synchronous future.
|
||||
}).catchError((Object? e) {
|
||||
_pending.remove(key);
|
||||
});
|
||||
}
|
||||
if (result != null) {
|
||||
_add(key, result!);
|
||||
return SynchronousFuture<LottieComposition>(result!);
|
||||
}
|
||||
assert(_cache.length <= maximumSize);
|
||||
return pendingResult!;
|
||||
}
|
||||
|
||||
void _add(Object key, LottieComposition result) {
|
||||
if (maximumSize > 0) {
|
||||
assert(_cache.length < maximumSize);
|
||||
_cache[key] = result;
|
||||
}
|
||||
assert(_cache.length <= maximumSize);
|
||||
}
|
||||
|
||||
/// The number of entries in the cache.
|
||||
int get count => _cache.length;
|
||||
}
|
||||
|
||||
final sharedLottieCache = LottieCache();
|
||||
|
@ -8,16 +8,13 @@ import 'load_image.dart';
|
||||
import 'lottie_provider.dart';
|
||||
|
||||
class MemoryLottie extends LottieProvider {
|
||||
MemoryLottie(this.bytes, {LottieImageProviderFactory? imageProviderFactory})
|
||||
: super(imageProviderFactory: imageProviderFactory);
|
||||
MemoryLottie(this.bytes, {super.imageProviderFactory});
|
||||
|
||||
final Uint8List bytes;
|
||||
|
||||
@override
|
||||
Future<LottieComposition> load() async {
|
||||
// TODO(xha): hash the list content
|
||||
var cacheKey = 'memory-${bytes.hashCode}-${bytes.lengthInBytes}';
|
||||
return sharedLottieCache.putIfAbsent(cacheKey, () async {
|
||||
Future<LottieComposition> load() {
|
||||
return sharedLottieCache.putIfAbsent(this, () async {
|
||||
var composition = await LottieComposition.fromBytes(bytes,
|
||||
imageProviderFactory: imageProviderFactory);
|
||||
for (var image in composition.images.values) {
|
||||
@ -41,6 +38,8 @@ class MemoryLottie extends LottieProvider {
|
||||
@override
|
||||
bool operator ==(dynamic other) {
|
||||
if (other.runtimeType != runtimeType) return false;
|
||||
|
||||
//TODO(xha): compare bytes content
|
||||
return other is MemoryLottie && other.bytes == bytes;
|
||||
}
|
||||
|
||||
|
@ -9,17 +9,14 @@ import 'lottie_provider.dart';
|
||||
import 'provider_io.dart' if (dart.library.html) 'provider_web.dart' as network;
|
||||
|
||||
class NetworkLottie extends LottieProvider {
|
||||
NetworkLottie(this.url,
|
||||
{this.headers, LottieImageProviderFactory? imageProviderFactory})
|
||||
: super(imageProviderFactory: imageProviderFactory);
|
||||
NetworkLottie(this.url, {this.headers, super.imageProviderFactory});
|
||||
|
||||
final String url;
|
||||
final Map<String, String>? headers;
|
||||
|
||||
@override
|
||||
Future<LottieComposition> load() async {
|
||||
var cacheKey = 'network-$url';
|
||||
return sharedLottieCache.putIfAbsent(cacheKey, () async {
|
||||
Future<LottieComposition> load() {
|
||||
return sharedLottieCache.putIfAbsent(this, () async {
|
||||
var resolved = Uri.base.resolve(url);
|
||||
var bytes = await network.loadHttp(resolved, headers: headers);
|
||||
|
||||
|
@ -13,7 +13,7 @@ import 'render_lottie.dart';
|
||||
class RawLottie extends LeafRenderObjectWidget {
|
||||
/// Creates a widget that displays a Lottie composition.
|
||||
const RawLottie({
|
||||
Key? key,
|
||||
super.key,
|
||||
this.composition,
|
||||
this.delegates,
|
||||
this.options,
|
||||
@ -25,8 +25,7 @@ class RawLottie extends LeafRenderObjectWidget {
|
||||
AlignmentGeometry? alignment,
|
||||
this.filterQuality,
|
||||
}) : progress = progress ?? 0.0,
|
||||
alignment = alignment ?? Alignment.center,
|
||||
super(key: key);
|
||||
alignment = alignment ?? Alignment.center;
|
||||
|
||||
/// The Lottie composition to display.
|
||||
final LottieComposition? composition;
|
||||
|
55
pubspec.lock
55
pubspec.lock
@ -7,21 +7,21 @@ packages:
|
||||
name: _fe_analyzer_shared
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "48.0.0"
|
||||
version: "50.0.0"
|
||||
analyzer:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: analyzer
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "5.0.0"
|
||||
version: "5.2.0"
|
||||
archive:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: archive
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.3.1"
|
||||
version: "3.3.5"
|
||||
args:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -56,7 +56,7 @@ packages:
|
||||
name: build_config
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
version: "1.1.1"
|
||||
build_daemon:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -70,21 +70,21 @@ packages:
|
||||
name: build_resolvers
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.10"
|
||||
version: "2.1.0"
|
||||
build_runner:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: build_runner
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.2.1"
|
||||
version: "2.3.2"
|
||||
build_runner_core:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: build_runner_core
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "7.2.4"
|
||||
version: "7.2.7"
|
||||
built_collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -98,7 +98,7 @@ packages:
|
||||
name: built_value
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "8.4.1"
|
||||
version: "8.4.2"
|
||||
characters:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -126,7 +126,7 @@ packages:
|
||||
name: code_builder
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.2.0"
|
||||
version: "4.3.0"
|
||||
collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -140,7 +140,7 @@ packages:
|
||||
name: convert
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.2"
|
||||
version: "3.1.1"
|
||||
crypto:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -199,21 +199,21 @@ packages:
|
||||
name: frontend_server_client
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.3"
|
||||
version: "3.2.0"
|
||||
glob:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: glob
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
version: "2.1.1"
|
||||
graphs:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: graphs
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
version: "2.2.0"
|
||||
http_multi_server:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -227,7 +227,7 @@ packages:
|
||||
name: http_parser
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.1"
|
||||
version: "4.0.2"
|
||||
io:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -241,28 +241,28 @@ packages:
|
||||
name: js
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.4"
|
||||
version: "0.6.5"
|
||||
json_annotation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: json_annotation
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.6.0"
|
||||
version: "4.7.0"
|
||||
lints:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: lints
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
version: "2.0.1"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: logging
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.2"
|
||||
version: "1.1.0"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -290,7 +290,7 @@ packages:
|
||||
name: mime
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.2"
|
||||
version: "1.0.3"
|
||||
package_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -305,6 +305,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.2"
|
||||
pointycastle:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pointycastle
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.6.2"
|
||||
pool:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -318,7 +325,7 @@ packages:
|
||||
name: pub_semver
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
version: "2.1.3"
|
||||
pubspec_parse:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -332,14 +339,14 @@ packages:
|
||||
name: shelf
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.2"
|
||||
version: "1.4.0"
|
||||
shelf_web_socket:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shelf_web_socket
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.2"
|
||||
version: "1.0.3"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
@ -372,7 +379,7 @@ packages:
|
||||
name: stream_transform
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
version: "2.1.0"
|
||||
string_scanner:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -421,7 +428,7 @@ packages:
|
||||
name: watcher
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
version: "1.0.2"
|
||||
web_socket_channel:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: lottie
|
||||
description: Render After Effects animations natively on Flutter. This package is a pure Dart implementation of a Lottie player.
|
||||
version: 2.0.0
|
||||
homepage: https://github.com/xvrh/lottie-flutter
|
||||
version: 2.1.0
|
||||
repository: https://github.com/xvrh/lottie-flutter
|
||||
|
||||
environment:
|
||||
sdk: '>=2.18.0 <3.0.0'
|
||||
|
@ -35,10 +35,10 @@ void main() {
|
||||
tester.binding.window.physicalSizeTestValue = size;
|
||||
tester.binding.window.devicePixelRatioTestValue = 1.0;
|
||||
|
||||
var image = await tester.runAsync(() =>
|
||||
var image = await tester.runAsync(() async =>
|
||||
loadImage(FileImage(File('example/assets/Images/WeAccept/img_0.png'))));
|
||||
|
||||
var composition = (await tester.runAsync(() =>
|
||||
var composition = (await tester.runAsync(() async =>
|
||||
FileLottie(File('example/assets/spinning_carrousel.zip')).load()))!;
|
||||
|
||||
var delegates = LottieDelegates(image: (composition, asset) {
|
||||
|
@ -4,11 +4,10 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lottie/lottie.dart';
|
||||
import 'package:lottie/src/providers/lottie_provider.dart';
|
||||
|
||||
void main() {
|
||||
tearDown(() {
|
||||
sharedLottieCache.clear();
|
||||
Lottie.cache.clear();
|
||||
});
|
||||
|
||||
testWidgets('Should settle if no animation', (tester) async {
|
||||
@ -324,6 +323,72 @@ void main() {
|
||||
expect(find.byKey(errorKey), findsNothing);
|
||||
expect(loadedCall, 1);
|
||||
});
|
||||
|
||||
testWidgets('Cache should be synchronous', (tester) async {
|
||||
var hamburgerData =
|
||||
Future.value(bytesForFile('example/assets/HamburgerArrow.json'));
|
||||
var mockAsset = FakeAssetBundle({
|
||||
'hamburger.json': hamburgerData,
|
||||
});
|
||||
|
||||
var loadedCall = 0;
|
||||
var lottieWidget = LottieBuilder.asset(
|
||||
'hamburger.json',
|
||||
bundle: mockAsset,
|
||||
onLoaded: (c) {
|
||||
++loadedCall;
|
||||
},
|
||||
);
|
||||
|
||||
await tester.pumpWidget(lottieWidget);
|
||||
expect(tester.widget<Lottie>(find.byType(Lottie)).composition, isNull);
|
||||
await tester.pump();
|
||||
expect(tester.widget<Lottie>(find.byType(Lottie)).composition, isNotNull);
|
||||
|
||||
await tester.pumpWidget(Column(
|
||||
children: [
|
||||
lottieWidget,
|
||||
lottieWidget,
|
||||
],
|
||||
));
|
||||
expect(tester.widget<Lottie>(find.byType(Lottie).at(0)).composition,
|
||||
isNotNull);
|
||||
expect(tester.widget<Lottie>(find.byType(Lottie).at(1)).composition,
|
||||
isNotNull);
|
||||
expect(loadedCall, 3);
|
||||
});
|
||||
|
||||
testWidgets('Cache can be cleared', (tester) async {
|
||||
var hamburgerData =
|
||||
Future.value(bytesForFile('example/assets/HamburgerArrow.json'));
|
||||
var mockAsset = FakeAssetBundle({
|
||||
'hamburger.json': hamburgerData,
|
||||
});
|
||||
|
||||
var loadedCall = 0;
|
||||
var lottieWidget = LottieBuilder.asset(
|
||||
'hamburger.json',
|
||||
bundle: mockAsset,
|
||||
onLoaded: (c) {
|
||||
++loadedCall;
|
||||
},
|
||||
);
|
||||
|
||||
await tester.pumpWidget(lottieWidget);
|
||||
expect(tester.widget<Lottie>(find.byType(Lottie)).composition, isNull);
|
||||
await tester.pump();
|
||||
expect(tester.widget<Lottie>(find.byType(Lottie)).composition, isNotNull);
|
||||
|
||||
Lottie.cache.clear();
|
||||
|
||||
await tester.pumpWidget(Center(
|
||||
child: lottieWidget,
|
||||
));
|
||||
expect(tester.widget<Lottie>(find.byType(Lottie)).composition, isNull);
|
||||
await tester.pump();
|
||||
expect(tester.widget<Lottie>(find.byType(Lottie)).composition, isNotNull);
|
||||
expect(loadedCall, 2);
|
||||
});
|
||||
}
|
||||
|
||||
class SynchronousFile extends Fake implements File {
|
||||
|
@ -7,8 +7,7 @@ class FilmStrip extends StatelessWidget {
|
||||
final Size size;
|
||||
|
||||
const FilmStrip(this.composition,
|
||||
{Key? key, required this.size, this.delegates})
|
||||
: super(key: key);
|
||||
{super.key, required this.size, this.delegates});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
Reference in New Issue
Block a user