From 4416a675ad991f74207a89556ef42656ef665dfe Mon Sep 17 00:00:00 2001 From: Luigi Rosso Date: Fri, 26 Apr 2019 12:32:39 -0700 Subject: [PATCH] Preventing double load. --- flare_flutter/lib/flare_actor.dart | 6 +++++- flare_flutter/lib/flare_render_box.dart | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/flare_flutter/lib/flare_actor.dart b/flare_flutter/lib/flare_actor.dart index 32fdd9e..578d52f 100644 --- a/flare_flutter/lib/flare_actor.dart +++ b/flare_flutter/lib/flare_actor.dart @@ -216,6 +216,9 @@ class FlareActorRenderObject extends FlareRenderBox { @override void load() { + if (_filename == null) { + return; + } super.load(); loadFlare(_filename).then((FlutterActor actor) { if (actor == null || actor.artboard == null) { @@ -302,7 +305,8 @@ class FlareActorRenderObject extends FlareRenderBox { } } - if (_artboard != null && _controller != null && + if (_artboard != null && + _controller != null && !_controller.advance(_artboard, elapsedSeconds)) { _controller?.isActive?.value = false; } diff --git a/flare_flutter/lib/flare_render_box.dart b/flare_flutter/lib/flare_render_box.dart index 42092db..65e4036 100644 --- a/flare_flutter/lib/flare_render_box.dart +++ b/flare_flutter/lib/flare_render_box.dart @@ -26,7 +26,7 @@ abstract class FlareRenderBox extends RenderBox { } _assetBundle = value; if (_assetBundle != null) { - load(); + _load(); } } @@ -81,7 +81,7 @@ abstract class FlareRenderBox extends RenderBox { super.attach(owner); updatePlayState(); if (_assets.isEmpty && assetBundle != null) { - load(); + _load(); } } @@ -202,11 +202,22 @@ abstract class FlareRenderBox extends RenderBox { /// Advance animations, physics, etc by elapsedSeconds. void advance(double elapsedSeconds); - /// Perform any loading logic necessary for this scene. - void load() { + bool _isLoading = false; + bool get isLoading => _isLoading; + + void _load() async { + if (_isLoading) { + return; + } + _isLoading = true; _unload(); + await load(); + _isLoading = false; } + /// Perform any loading logic necessary for this scene. + void load() async {} + void _unload() { for (final FlareCacheAsset asset in _assets) { asset.deref();