你好,我尝试使用flutter中的滑块来实现Flare动画。我创建了五个键(1、2、3、4、5),它们调用特定的Flare动画,这些动画在Flare编辑器中工作得很好,但是当我启动应用程序时,我遇到了一些添加偏移、取消偏移或显示的动画项的问题,这是随机的……
我用不同的形状创建了一个简单的测试,使用不同的工具创建了Flare编辑器圆、Hexagone、Pen,而我目前对使用Pen工具创建的形状有困难,因为Pen工具会自动删除或随机出现。
扩口版本:扩口颤振:^1.5.2
chronology of the gif
value=0.0 black shape is showed // all is good
value=25.0 black shape is showed // all is good
value=0.0 black shape disepear // not good
value=25.0 black shape disepear // not good
value=0.0 black shape disepear // not good
value=25.0 black shape disepear // not good
reload app
value=0.0 black shape is showed // all is good
value=25.0 black shape is showed // all is good
下面是例子
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final FlareControls controls = FlareControls();
double slidervalue;
@override
void initState() {
slidervalue=0.0;
controls.play("1");
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Container (
width:150,
height: 150,
child :new FlareActor("assets/flare_test.flr", alignment:Alignment.center, fit:BoxFit.contain, animation:"idle" , controller:controls,
)
),
Slider(
value: slidervalue,
min: 0,
max: 100,
divisions: 4,
label: "$slidervalue",
onChanged: (value) {
setState(() {
slidervalue = value;
if(slidervalue==0.0){
controls.play("1");
}
if(slidervalue==25){
controls.play("2");
}
if(slidervalue==50){
controls.play("3");
}
if(slidervalue==75){
controls.play("4");
}
if (slidervalue==100){
controls.play("5");
}
});
},
),
],
),
)
);
}
}
如果我用更改状态中断动画,这里还有一个修改init原点的观察。我在最后一个位置动画中观察到初始原点的偏移。而不是重新启动init-origin
在这个例子中,我不知道为什么翻译使用最后一个旋转原点,而旋转保持初始原点按下。
在最后一个例子中,为什么第一次按下按钮时一切都好,第二次松开翻译轴时一切都好?
我在Flare上发布了这个问题,但可能我做错了。
最佳答案
我丑陋的解决方案。我为FlareActor的每个键使用一个堆栈,当滑块更改值、键更改和我是否可见时,FlareActor依赖于所选键。工作,但它不美…
final FlareControls _controls = FlareControls();
final FlareControls _controls2 = FlareControls();
final FlareControls _controls3 = FlareControls();
final FlareControls _controls4 = FlareControls();
final FlareControls _controls5 = FlareControls();
bool visibilitanim1;
bool visibilitanim2;
bool visibilitanim3;
bool visibilitanim4;
bool visibilitanim5;
double slidervalue;
@override
void initState() {
slidervalue=0;
visibilitanim1=true;
visibilitanim2=false;
visibilitanim3=false;
visibilitanim4=false;
visibilitanim5=false;
super.initState();
}
void _changed(bool visibility, String field) {
setState(() {
if (field == "anim1"){
visibilitanim1 = visibility;
}
if (field == "anim2"){
visibilitanim2 = visibility;
}
if (field == "anim3"){
visibilitanim3 = visibility;
}
if (field == "anim4"){
visibilitanim4 = visibility;
}
if (field == "anim5"){
visibilitanim5 = visibility;
}
});
} //modifi
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Stack (
children: <Widget>[
visibilitanim1 ? new Container (
width:150,
height: 150,
child :new FlareActor("assets/flare_test.flr", alignment:Alignment.center, fit:BoxFit.contain, animation:"1" , controller:_controls,
)
) : Container(),
visibilitanim2 ? new Container (
width:150,
height: 150,
child :new FlareActor("assets/flare_test.flr", alignment:Alignment.center, fit:BoxFit.contain, animation:"2" , controller:_controls2,
)
): Container(),
visibilitanim3 ? new Container (
width:150,
height: 150,
child :new FlareActor("assets/flare_test.flr", alignment:Alignment.center, fit:BoxFit.contain, animation:"3" , controller:_controls3,
)
): Container(),
visibilitanim4 ? new Container (
width:150,
height: 150,
child :new FlareActor("assets/flare_test.flr", alignment:Alignment.center, fit:BoxFit.contain, animation:"4" , controller:_controls4,
)
): Container(),
visibilitanim5 ? new Container (
width:150,
height: 150,
child :new FlareActor("assets/flare_test.flr", alignment:Alignment.center, fit:BoxFit.contain, animation:"5" , controller:_controls5,
)
): Container(),
],
),
Slider(
value: slidervalue,
min: 0,
max: 100,
divisions: 4,
label: "$slidervalue",
onChanged: (value) {
setState(() {
slidervalue = value;
if(slidervalue==0.0){
_changed(true, "anim1");
_controls.play("1");
_changed(false, "anim2");
_changed(false, "anim3");
_changed(false, "anim4");
_changed(false, "anim5");
}
if(slidervalue==25){
_changed(true, "anim2");
_controls2.play("2");
_changed(false, "anim1");
_changed(false, "anim3");
_changed(false, "anim4");
_changed(false, "anim5");
}
if(slidervalue==50){
_changed(true, "anim3");
_controls3.play("3");
_changed(false, "anim1");
_changed(false, "anim2");
_changed(false, "anim4");
_changed(false, "anim5");
}
if(slidervalue==75){
_changed(true, "anim4");
_controls4.play("4");
_changed(false, "anim1");
_changed(false, "anim2");
_changed(false, "anim3");
_changed(false, "anim5");
}
if (slidervalue==100){
_changed(true, "anim5");
_controls5.play("5");
_changed(false, "anim1");
_changed(false, "anim2");
_changed(false, "anim3");
_changed(false, "anim4");
}
});
},
),