Flare-Flutter icon indicating copy to clipboard operation
Flare-Flutter copied to clipboard

Changing color doesn't work with 1.3.11+

Open johnyyhign opened this issue 6 years ago • 3 comments

With 1.3.11 and up, changing the FlareActor color doesn't work. I can set eg red color as a prop and it works, but when changing color with eg setState or basically on rebuild, the color isn't updated.

So: State: Color _color = Colors.red; Build: FlareActor(color: _color, ... Somewhere there is button that has onPress: () => setState(() => _color = Colors.blue)

So the actor is started red, but after pressing the button, it is still red :/ Works fine on 1.3.10 and below (changes the actor to blue)

johnyyhign avatar Apr 17 '19 16:04 johnyyhign

As of Flare 1.3.11+ you're required to re-activate the controller. If the controller returns false in its advance method, the FlareActor stops updating. So you can either let the controller advance return true (which will unnecessarily drain performance) or simply re-activate the controller when you change its state. You can do this as is shown in the example here: https://github.com/2d-inc/Flare-Flutter/blob/d2b58205c816c23f3396ffb866dd6a6f7f9771cf/example/change_color/lib/main.dart#L64

You'd normally make the controller a separate object but for the purposes of this example the widget directly implements the controller.

luigi-rosso avatar Apr 17 '19 17:04 luigi-rosso

Running on 1.5.0 and fill color on basic shapes works for me. What I have been trying to achieve for several hours now: Is there any way to make the color affect gradients? Just overwriting both colors would be fine - I want simple 100 to 0 opacity. Unfortunately the color is simply ignored for all kind of gradient fills :( Any ideas?

chu86 avatar May 05 '19 18:05 chu86

As of Flare 1.3.11+ you're required to re-activate the controller. If the controller returns false in its advance method, the FlareActor stops updating. So you can either let the controller advance return true (which will unnecessarily drain performance) or simply re-activate the controller when you change its state. You can do this as is shown in the example here: https://github.com/2d-inc/Flare-Flutter/blob/d2b58205c816c23f3396ffb866dd6a6f7f9771cf/example/change_color/lib/main.dart#L64

You'd normally make the controller a separate object but for the purposes of this example the widget directly implements the controller.

This isn't easy for state management outside the widget that the actor's in.

hacker1024 avatar Dec 18 '19 05:12 hacker1024