diff --git a/CHANGELOG.md b/CHANGELOG.md index c2f54807..7865b702 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 3.0.0-alpha.3 +- Reduce the max memory used when using `enableRenderCache` (now limited to 50MB) +- Allow to configure the memory with a global settings: +```dart +Lottie.renderCacheMaxMemory = 75000000; +``` + ## 3.0.0-alpha.2 - Implement auto-orient - Add support for layer blend mode diff --git a/example/pubspec.lock b/example/pubspec.lock index 5c4028d7..69b877dd 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -161,7 +161,7 @@ packages: path: ".." relative: true source: path - version: "3.0.0-alpha.2" + version: "3.0.0-alpha.3" matcher: dependency: transitive description: @@ -254,10 +254,10 @@ packages: dependency: transitive description: name: plugin_platform_interface - sha256: da3fdfeccc4d4ff2da8f8c556704c08f912542c5fb3cf2233ed75372384a034d + sha256: f4f88d4a900933e7267e2b353594774fc0d07fb072b47eedcd5b54e1ea3269f8 url: "https://pub.dev" source: hosted - version: "2.1.6" + version: "2.1.7" pointycastle: dependency: transitive description: diff --git a/lib/src/lottie.dart b/lib/src/lottie.dart index 5047b2c7..e26f290d 100644 --- a/lib/src/lottie.dart +++ b/lib/src/lottie.dart @@ -5,6 +5,7 @@ import 'composition.dart'; import 'l.dart'; import 'lottie_builder.dart'; import 'providers/lottie_provider.dart'; +import 'render_cache.dart'; /// A widget to display a loaded [LottieComposition]. /// The [controller] property allows to specify a custom AnimationController that @@ -15,6 +16,15 @@ class Lottie extends StatefulWidget { /// The cache instance for recently loaded Lottie compositions. static LottieCache get cache => sharedLottieCache; + /// The maximum memory to use when using `enableRenderCache`. + /// When the limit is reached, new frames are not put in the cache until some + /// memory is released. When an animation disappear from the screen, its memory + /// is released immediately. + static int get renderCacheMaxMemory => globalRenderCache.maxMemory; + static set renderCacheMaxMemory(int value) { + globalRenderCache.maxMemory = value; + } + const Lottie({ super.key, required this.composition, @@ -354,7 +364,7 @@ class Lottie extends StatefulWidget { /// visible on the screen (with all transforms applied). /// /// In order to not exceed the memory limit of a device, the cache is constrained - /// to maximum 100MiB. After that, animations are not cached anymore. + /// to maximum 50MB. After that, animations are not cached anymore. final bool enableRenderCache; static bool get traceEnabled => L.traceEnabled; diff --git a/lib/src/lottie_builder.dart b/lib/src/lottie_builder.dart index 0dcadd1a..03563f49 100644 --- a/lib/src/lottie_builder.dart +++ b/lib/src/lottie_builder.dart @@ -435,7 +435,7 @@ class LottieBuilder extends StatefulWidget { /// visible on the screen (with all transforms applied). /// /// In order to not exceed the memory limit of a device, the cache is constrained - /// to maximum 100MiB. After that, animations are not cached anymore. + /// to maximum 50MB. After that, animations are not cached anymore. final bool? enableRenderCache; @override diff --git a/lib/src/raw_lottie.dart b/lib/src/raw_lottie.dart index 8689921f..d111aab8 100644 --- a/lib/src/raw_lottie.dart +++ b/lib/src/raw_lottie.dart @@ -98,7 +98,7 @@ class RawLottie extends LeafRenderObjectWidget { /// visible on the screen (with all transforms applied). /// /// In order to not exceed the memory limit of a device, the cache is constrained - /// to maximum 100MiB. After that, animations are not cached anymore. + /// to maximum 50MB. After that, animations are not cached anymore. final bool enableRenderCache; final FilterQuality? filterQuality; diff --git a/lib/src/render_cache.dart b/lib/src/render_cache.dart index 2d3f1c73..ec462b9a 100644 --- a/lib/src/render_cache.dart +++ b/lib/src/render_cache.dart @@ -13,9 +13,11 @@ class RenderCache { final entries = {}; final handles = {}; - /// The maximum memory this cache will use (default 100MiB) + /// The maximum memory this cache will use (default 50MB) /// It should refuse to create new images if the size is exceeded. - final int maxMemory = 100 << 20; + static const int defaultMaxMemory = 50000000; + + int maxMemory = defaultMaxMemory; bool enableDebugBackground = false; diff --git a/pubspec.lock b/pubspec.lock index 7162ec6a..a833af15 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -93,10 +93,10 @@ packages: dependency: "direct dev" description: name: dart_style - sha256: abd7625e16f51f554ea244d090292945ec4d4be7bfbaf2ec8cccea568919d334 + sha256: "40ae61a5d43feea6d24bd22c0537a6629db858963b99b4bc1c3db80676f32368" url: "https://pub.dev" source: hosted - version: "2.3.3" + version: "2.3.4" fake_async: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 70a73f5d..5c101795 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: lottie description: Render After Effects animations natively on Flutter. This package is a pure Dart implementation of a Lottie player. -version: 3.0.0-alpha.2 +version: 3.0.0-alpha.3 repository: https://github.com/xvrh/lottie-flutter environment: