From 92d9dcb9292b090ef11e394bf186e75fd9dcdcb5 Mon Sep 17 00:00:00 2001 From: Luigi Rosso Date: Wed, 24 Jul 2019 13:46:46 -0700 Subject: [PATCH] Squashed commit of the following: commit 1e5394b37bdb08e023ebef58ccf40c89add80087 Author: Luigi Rosso Date: Wed Jul 24 11:47:01 2019 -0700 Adding artboard option. commit 6f6000f3600a3f20c7a605cf6b20df5380c88d44 Author: Luigi Rosso Date: Mon Jul 8 21:19:43 2019 -0700 Squashed commit of the following: commit f24a688baf29916ae070404fe0c656c96e5c144e Author: Luigi Rosso Date: Mon Jul 8 21:18:32 2019 -0700 Squashed commit of the following: commit 085a15c38e883149b2269eb5809c5e00b1b848b9 Author: Luigi Rosso Date: Mon Jul 8 21:17:28 2019 -0700 Squashed commit of the following: commit 56cea07339c72f7abb7dbc8354c4982157805035 Author: Luigi Rosso Date: Mon Jul 8 21:15:07 2019 -0700 Updating stable to latest flare_flutter from dev. commit 28846c58bec6cee40a23b9ab9412bd291987e0b1 Merge: e1a55f9 52d5e6e Author: Luigi Rosso Date: Sat Jul 6 11:06:01 2019 -0700 Merge pull request #121 from 2d-inc/master Merging intrinsic_size_experiment changes commit e1a55f91331e0b7cd47ec43203b594b986395523 Merge: 5533e73 15682ac Author: Luigi Rosso Date: Sat Jul 6 10:28:42 2019 -0700 Merge pull request #119 from 2d-inc/master Check for null children before iterating for initialization. commit 5533e73cbb2322a4267485c5ac13bf21f9f2da68 Merge: 01387cd a17469b Author: Luigi Rosso Date: Wed Jul 3 10:40:12 2019 -0700 Merge pull request #116 from 2d-inc/master Remove console spam. commit 01387cdb2df3c46119179feacae43f28f2b11257 Merge: 0ee2efe 525613e Author: Luigi Rosso Date: Tue Jul 2 18:13:31 2019 -0700 Merge pull request #115 from 2d-inc/master Instance shape node from actor. commit 0ee2efeb22ee2c2ecbc6a265383b337ad02768c9 Merge: 8f04aa6 0230aab Author: Luigi Rosso Date: Thu Jun 20 16:27:00 2019 -0700 Merge pull request #108 from 2d-inc/master Fixing rectangle and clips. commit 8f04aa6d355b3b5c0ed1ba515988347510cefbb6 Merge: 6606b73 865e090 Author: Luigi Rosso Date: Thu Jun 13 16:07:43 2019 -0700 Merge pull request #102 from 2d-inc/master Updating dev branch. commit 6606b73bf4f7b87105a6febfbb5f2167cf8b8977 Merge: 396cd88 f147157 Author: Luigi Rosso Date: Tue Jun 4 11:59:29 2019 -0700 Merge branch 'master' into dev commit 396cd88df7638b86e55b4467364fa2c41cde1558 Merge: 006d85b 9db2d97 Author: Luigi Rosso Date: Mon May 20 10:56:46 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter into dev commit 006d85bc53a61174bd2e2c2cf3321ff85312c1c7 Merge: c51192d 850ea83 Author: Luigi Rosso Date: Mon May 20 10:45:58 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter into dev commit c51192dec50dec034d121f6aad7d2e8733c7e279 Merge: 4aebb0f 4e9961b Author: Luigi Rosso Date: Thu May 9 11:44:40 2019 -0700 Merge pull request #89 from 2d-inc/master Update indices to 16 bit unsigned, compatibility with flutter master. commit 4aebb0ff5b98c7bcf2183c6bac8226cc7ddf5402 Merge: 113d791 63c1d05 Author: Luigi Rosso Date: Fri Apr 26 13:42:11 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter into dev commit 113d791606c6b6fb7b19ca616e8b7282e4f0b610 Merge: 2ec15af 4416a67 Author: Luigi Rosso Date: Fri Apr 26 12:33:04 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter into dev commit 2ec15af0042696de7d997cbfdcb6deaf55463af2 Merge: d8defc4 2dbb7ab Author: Luigi Rosso Date: Wed Apr 24 12:07:45 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter into dev commit d8defc4c07571ce8287f26791cf38992fffaef75 Author: Luigi Rosso Date: Wed Apr 24 10:15:51 2019 -0700 Fixing relative path for flare_dart. commit 2e1fcaaa944d4d795d21382418935b8ffa6c1615 Author: Luigi Rosso Date: Wed Apr 24 10:14:38 2019 -0700 Updating flare_dart dependency to dev branch of Flare-Flutter. commit 28846c58bec6cee40a23b9ab9412bd291987e0b1 Merge: e1a55f9 52d5e6e Author: Luigi Rosso Date: Sat Jul 6 11:06:01 2019 -0700 Merge pull request #121 from 2d-inc/master Merging intrinsic_size_experiment changes commit e1a55f91331e0b7cd47ec43203b594b986395523 Merge: 5533e73 15682ac Author: Luigi Rosso Date: Sat Jul 6 10:28:42 2019 -0700 Merge pull request #119 from 2d-inc/master Check for null children before iterating for initialization. commit 5533e73cbb2322a4267485c5ac13bf21f9f2da68 Merge: 01387cd a17469b Author: Luigi Rosso Date: Wed Jul 3 10:40:12 2019 -0700 Merge pull request #116 from 2d-inc/master Remove console spam. commit 01387cdb2df3c46119179feacae43f28f2b11257 Merge: 0ee2efe 525613e Author: Luigi Rosso Date: Tue Jul 2 18:13:31 2019 -0700 Merge pull request #115 from 2d-inc/master Instance shape node from actor. commit 0ee2efeb22ee2c2ecbc6a265383b337ad02768c9 Merge: 8f04aa6 0230aab Author: Luigi Rosso Date: Thu Jun 20 16:27:00 2019 -0700 Merge pull request #108 from 2d-inc/master Fixing rectangle and clips. commit 8f04aa6d355b3b5c0ed1ba515988347510cefbb6 Merge: 6606b73 865e090 Author: Luigi Rosso Date: Thu Jun 13 16:07:43 2019 -0700 Merge pull request #102 from 2d-inc/master Updating dev branch. commit 6606b73bf4f7b87105a6febfbb5f2167cf8b8977 Merge: 396cd88 f147157 Author: Luigi Rosso Date: Tue Jun 4 11:59:29 2019 -0700 Merge branch 'master' into dev commit 396cd88df7638b86e55b4467364fa2c41cde1558 Merge: 006d85b 9db2d97 Author: Luigi Rosso Date: Mon May 20 10:56:46 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter into dev commit 006d85bc53a61174bd2e2c2cf3321ff85312c1c7 Merge: c51192d 850ea83 Author: Luigi Rosso Date: Mon May 20 10:45:58 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter into dev commit c51192dec50dec034d121f6aad7d2e8733c7e279 Merge: 4aebb0f 4e9961b Author: Luigi Rosso Date: Thu May 9 11:44:40 2019 -0700 Merge pull request #89 from 2d-inc/master Update indices to 16 bit unsigned, compatibility with flutter master. commit 4aebb0ff5b98c7bcf2183c6bac8226cc7ddf5402 Merge: 113d791 63c1d05 Author: Luigi Rosso Date: Fri Apr 26 13:42:11 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter into dev commit 113d791606c6b6fb7b19ca616e8b7282e4f0b610 Merge: 2ec15af 4416a67 Author: Luigi Rosso Date: Fri Apr 26 12:33:04 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter into dev commit 2ec15af0042696de7d997cbfdcb6deaf55463af2 Merge: d8defc4 2dbb7ab Author: Luigi Rosso Date: Wed Apr 24 12:07:45 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter into dev commit d8defc4c07571ce8287f26791cf38992fffaef75 Author: Luigi Rosso Date: Wed Apr 24 10:15:51 2019 -0700 Fixing relative path for flare_dart. commit 2e1fcaaa944d4d795d21382418935b8ffa6c1615 Author: Luigi Rosso Date: Wed Apr 24 10:14:38 2019 -0700 Updating flare_dart dependency to dev branch of Flare-Flutter. commit 085a15c38e883149b2269eb5809c5e00b1b848b9 Author: Luigi Rosso Date: Mon Jul 8 21:17:28 2019 -0700 Squashed commit of the following: commit 56cea07339c72f7abb7dbc8354c4982157805035 Author: Luigi Rosso Date: Mon Jul 8 21:15:07 2019 -0700 Updating stable to latest flare_flutter from dev. commit 28846c58bec6cee40a23b9ab9412bd291987e0b1 Merge: e1a55f9 52d5e6e Author: Luigi Rosso Date: Sat Jul 6 11:06:01 2019 -0700 Merge pull request #121 from 2d-inc/master Merging intrinsic_size_experiment changes commit e1a55f91331e0b7cd47ec43203b594b986395523 Merge: 5533e73 15682ac Author: Luigi Rosso Date: Sat Jul 6 10:28:42 2019 -0700 Merge pull request #119 from 2d-inc/master Check for null children before iterating for initialization. commit 5533e73cbb2322a4267485c5ac13bf21f9f2da68 Merge: 01387cd a17469b Author: Luigi Rosso Date: Wed Jul 3 10:40:12 2019 -0700 Merge pull request #116 from 2d-inc/master Remove console spam. commit 01387cdb2df3c46119179feacae43f28f2b11257 Merge: 0ee2efe 525613e Author: Luigi Rosso Date: Tue Jul 2 18:13:31 2019 -0700 Merge pull request #115 from 2d-inc/master Instance shape node from actor. commit 0ee2efeb22ee2c2ecbc6a265383b337ad02768c9 Merge: 8f04aa6 0230aab Author: Luigi Rosso Date: Thu Jun 20 16:27:00 2019 -0700 Merge pull request #108 from 2d-inc/master Fixing rectangle and clips. commit 8f04aa6d355b3b5c0ed1ba515988347510cefbb6 Merge: 6606b73 865e090 Author: Luigi Rosso Date: Thu Jun 13 16:07:43 2019 -0700 Merge pull request #102 from 2d-inc/master Updating dev branch. commit 6606b73bf4f7b87105a6febfbb5f2167cf8b8977 Merge: 396cd88 f147157 Author: Luigi Rosso Date: Tue Jun 4 11:59:29 2019 -0700 Merge branch 'master' into dev commit 396cd88df7638b86e55b4467364fa2c41cde1558 Merge: 006d85b 9db2d97 Author: Luigi Rosso Date: Mon May 20 10:56:46 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter into dev commit 006d85bc53a61174bd2e2c2cf3321ff85312c1c7 Merge: c51192d 850ea83 Author: Luigi Rosso Date: Mon May 20 10:45:58 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter into dev commit c51192dec50dec034d121f6aad7d2e8733c7e279 Merge: 4aebb0f 4e9961b Author: Luigi Rosso Date: Thu May 9 11:44:40 2019 -0700 Merge pull request #89 from 2d-inc/master Update indices to 16 bit unsigned, compatibility with flutter master. commit 4aebb0ff5b98c7bcf2183c6bac8226cc7ddf5402 Merge: 113d791 63c1d05 Author: Luigi Rosso Date: Fri Apr 26 13:42:11 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter into dev commit 113d791606c6b6fb7b19ca616e8b7282e4f0b610 Merge: 2ec15af 4416a67 Author: Luigi Rosso Date: Fri Apr 26 12:33:04 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter into dev commit 2ec15af0042696de7d997cbfdcb6deaf55463af2 Merge: d8defc4 2dbb7ab Author: Luigi Rosso Date: Wed Apr 24 12:07:45 2019 -0700 Merge branch 'master' of https://github.com/2d-inc/Flare-Flutter into dev commit d8defc4c07571ce8287f26791cf38992fffaef75 Author: Luigi Rosso Date: Wed Apr 24 10:15:51 2019 -0700 Fixing relative path for flare_dart. commit 2e1fcaaa944d4d795d21382418935b8ffa6c1615 Author: Luigi Rosso Date: Wed Apr 24 10:14:38 2019 -0700 Updating flare_dart dependency to dev branch of Flare-Flutter. --- flare_dart/CHANGELOG.md | 4 + flare_dart/lib/actor.dart | 4 + flare_flutter/CHANGELOG.md | 6 + flare_flutter/lib/flare_actor.dart | 141 +++++++++++++++++------- flare_flutter/lib/flare_render_box.dart | 4 +- 5 files changed, 115 insertions(+), 44 deletions(-) diff --git a/flare_dart/CHANGELOG.md b/flare_dart/CHANGELOG.md index deea0f1..e3ff9ea 100644 --- a/flare_dart/CHANGELOG.md +++ b/flare_dart/CHANGELOG.md @@ -1,3 +1,7 @@ +## [1.4.4] - 2019-07-24 11:43:51 + +Adding getArtboard method to Actor class. Allows finding artboards by name. + ## [1.4.3] - 2019-07-06 11:08:53 Some cleanup done while fixing issue #104 (using intrinsic artboard size as an option). diff --git a/flare_dart/lib/actor.dart b/flare_dart/lib/actor.dart index e854667..8d7acfd 100644 --- a/flare_dart/lib/actor.dart +++ b/flare_dart/lib/actor.dart @@ -22,6 +22,10 @@ abstract class Actor { Actor(); ActorArtboard get artboard => _artboards.isNotEmpty ? _artboards.first : null; + ActorArtboard getArtboard(String name) => name == null + ? artboard + : _artboards.firstWhere((artboard) => artboard?.name == name, + orElse: () => null); int get version { return _version; diff --git a/flare_flutter/CHANGELOG.md b/flare_flutter/CHANGELOG.md index 19fe297..036497e 100644 --- a/flare_flutter/CHANGELOG.md +++ b/flare_flutter/CHANGELOG.md @@ -1,3 +1,9 @@ +## [1.5.5] - 2019-07-24 11:44:36 + + - Adding artboard option to FlareActor. Use this to change which artboard gets displayed by the FlareActor widget. + - Fixed incorrect signature of load method. If you were deriving FlareRenderBox, you'll need to update it to match. It's a minor change from void to Future. + - Added some documentation to the FlareActor parameters. + ## [1.5.4] - 2019-07-08 21:10:50 - Using Uint16List for vertex indices now that Flutter Stable has been updated. diff --git a/flare_flutter/lib/flare_actor.dart b/flare_flutter/lib/flare_actor.dart index 818cb20..374804e 100644 --- a/flare_flutter/lib/flare_actor.dart +++ b/flare_flutter/lib/flare_actor.dart @@ -12,31 +12,67 @@ import 'flare_controller.dart'; typedef void FlareCompletedCallback(String name); class FlareActor extends LeafRenderObjectWidget { + /// Name of the Flare file to be loaded from the AssetBundle. final String filename; + + /// The name of the artboard to display. + final String artboard; + + /// The name of the animation to play. final String animation; + + /// When true, the animation will be applied at the end of its duration. final bool snapToEnd; + + /// The BoxFit strategy used to scale the Flare content into the + /// bounds of this widget. final BoxFit fit; + + /// The alignment that will be applied in conjuction to the [fit] to align + /// the Flare content within the bounds of this widget. final Alignment alignment; + + /// When true, animations do not advance. final bool isPaused; + + /// When true, the Flare content will be clipped against the bounds of this + /// widget. final bool shouldClip; + + /// The [FlareController] used to drive animations/mixing/procedural hierarchy + /// manipulation of the Flare contents. final FlareController controller; + + /// Callback invoked when [animation] has completed. If [animation] is looping + /// this callback is never invoked. final FlareCompletedCallback callback; + + /// The color to override any fills/strokes with. final Color color; + + /// The name of the node to use to determine the bounds of the content. + /// When null it will default to the bounds of the artboard. final String boundsNode; + + /// When true the intrinsic size of the artboard will be used as the + /// dimensions of this widget. final bool sizeFromArtboard; - const FlareActor(this.filename, - {this.boundsNode, - this.animation, - this.fit = BoxFit.contain, - this.alignment = Alignment.center, - this.isPaused = false, - this.snapToEnd = false, - this.controller, - this.callback, - this.color, - this.shouldClip = true, - this.sizeFromArtboard = false}); + const FlareActor( + this.filename, { + this.boundsNode, + this.animation, + this.fit = BoxFit.contain, + this.alignment = Alignment.center, + this.isPaused = false, + this.snapToEnd = false, + this.controller, + this.callback, + this.color, + this.shouldClip = true, + this.sizeFromArtboard = false, + this.artboard, + }); @override RenderObject createRenderObject(BuildContext context) { @@ -53,7 +89,8 @@ class FlareActor extends LeafRenderObjectWidget { ..color = color ..shouldClip = shouldClip ..boundsNodeName = boundsNode - ..useIntrinsicSize = sizeFromArtboard; + ..useIntrinsicSize = sizeFromArtboard + ..artboardName = artboard; } @override @@ -70,7 +107,8 @@ class FlareActor extends LeafRenderObjectWidget { ..color = color ..shouldClip = shouldClip ..boundsNodeName = boundsNode - ..useIntrinsicSize = sizeFromArtboard; + ..useIntrinsicSize = sizeFromArtboard + ..artboardName = artboard; } @override @@ -94,12 +132,24 @@ class FlareAnimationLayer { class FlareActorRenderObject extends FlareRenderBox { Mat2D _lastControllerViewTransform; String _filename; + String _artboardName; String _animationName; String _boundsNodeName; FlareController _controller; FlareCompletedCallback _completedCallback; bool snapToEnd = false; bool _isPaused = false; + FlutterActor _actor; + + String get artboardName => _artboardName; + set artboardName(String name) { + if (_artboardName == name) { + return; + } + _artboardName = name; + _instanceArtboard(); + } + bool get isPaused => _isPaused; set isPaused(bool value) { if (_isPaused == value) { @@ -213,38 +263,45 @@ class FlareActorRenderObject extends FlareRenderBox { load(); } + bool _instanceArtboard() { + if (_actor == null || _actor.artboard == null) { + return false; + } + FlutterActorArtboard artboard = _actor + .getArtboard(_artboardName) + .makeInstance() as FlutterActorArtboard; + artboard.initializeGraphics(); + _artboard = artboard; + intrinsicSize = Size(artboard.width, artboard.height); + _artboard.overrideColor = _color == null + ? null + : Float32List.fromList([ + _color.red / 255.0, + _color.green / 255.0, + _color.blue / 255.0, + _color.opacity + ]); + _artboard.advance(0.0); + updateBounds(); + + if (_controller != null) { + _controller.initialize(_artboard); + } + _updateAnimation(onlyWhenMissing: true); + markNeedsPaint(); + return true; + } + @override - void load() { + Future load() async { if (_filename == null) { return; } - super.load(); - loadFlare(_filename).then((FlutterActor actor) { - if (actor == null || actor.artboard == null) { - return; - } - FlutterActorArtboard artboard = - actor.artboard.makeInstance() as FlutterActorArtboard; - artboard.initializeGraphics(); - _artboard = artboard; - intrinsicSize = Size(artboard.width, artboard.height); - _artboard.overrideColor = _color == null - ? null - : Float32List.fromList([ - _color.red / 255.0, - _color.green / 255.0, - _color.blue / 255.0, - _color.opacity - ]); - _artboard.advance(0.0); - updateBounds(); - - if (_controller != null) { - _controller.initialize(_artboard); - } - _updateAnimation(onlyWhenMissing: true); - markNeedsPaint(); - }); + _actor = await loadFlare(_filename); + if (_actor == null || _actor.artboard == null) { + return; + } + _instanceArtboard(); } FlareCompletedCallback get completed => _completedCallback; diff --git a/flare_flutter/lib/flare_render_box.dart b/flare_flutter/lib/flare_render_box.dart index 9b5879f..46be707 100644 --- a/flare_flutter/lib/flare_render_box.dart +++ b/flare_flutter/lib/flare_render_box.dart @@ -236,7 +236,7 @@ abstract class FlareRenderBox extends RenderBox { bool _isLoading = false; bool get isLoading => _isLoading; - void _load() async { + Future _load() async { if (_isLoading) { return; } @@ -247,7 +247,7 @@ abstract class FlareRenderBox extends RenderBox { } /// Perform any loading logic necessary for this scene. - void load() async {} + Future load() async {} void _unload() { for (final FlareCacheAsset asset in _assets) {