Flutter AnimatedContainer正在破坏其他动画
我使用动画旋转梯度的同时,当用户按下容器,我想增加容器的大小 当我使用容器而不是AnimatedContainer渐变动画按预期工作时,但当我使用AnimatedContainer替换容器时,渐变动画工作不正常(意思是:将0旋转到2*math.pi后,再次重置并启动动画,我希望它继续旋转。)Flutter AnimatedContainer正在破坏其他动画,flutter,flutter-layout,flutter-animation,Flutter,Flutter Layout,Flutter Animation,我使用动画旋转梯度的同时,当用户按下容器,我想增加容器的大小 当我使用容器而不是AnimatedContainer渐变动画按预期工作时,但当我使用AnimatedContainer替换容器时,渐变动画工作不正常(意思是:将0旋转到2*math.pi后,再次重置并启动动画,我希望它继续旋转。) 导入“包装:颤振/材料.省道”; 导入'dart:math'作为数学; 类Delete扩展StatefulWidget{ 删除({Key}):超级(Key:Key); @凌驾 _DeleteState cr
导入“包装:颤振/材料.省道”;
导入'dart:math'作为数学;
类Delete扩展StatefulWidget{
删除({Key}):超级(Key:Key);
@凌驾
_DeleteState createState()=>\u DeleteState();
}
类_DeleteState使用SingleTickerProviderStateMixin扩展状态{
动画(动画),;
动画控制器_控制器;
双按钮大小=170;
@凌驾
void initState(){
super.initState();
_控制器=
AnimationController(vsync:this,duration:duration(秒:10));
_动画=Tween(开始:0,结束:2*math.pi)
…addListener(){
setState((){});
});
_controller.repeat();
}
@凌驾
无效处置(){
_controller.dispose();
super.dispose();
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“”),
),
主体:容器(
儿童:手势检测器(
onLongPress:(){
设置状态(){
_playButtonSize=185;
});
},
onLongPressEnd:(结束){
设置状态(){
_playButtonSize=170;
});
},
子:动画容器(
持续时间:持续时间(毫秒:100),
宽度:_playbutonSize,
高度:_playbutonSize,
填充:所有边缘设置(17.0),
装饰:盒子装饰(
形状:BoxShape.circle,
渐变:扫描渐变(
颜色:[
颜色,蓝色,
颜色,粉色,
颜色,橙色,
颜色,黄色,
颜色。蓝色
],
中心:对齐(-0.50,-0.0),
endAngle:_animation.value+(2*math.pi),
startAngle:_animation.value,
tileMode:tileMode.重复,
),
boxShadow:[
箱形阴影(
颜色:颜色,白色,
半径:4.0,
),
],
),
子:图标(
Icons.email,
尺码:50,
)),
),
));
}
}
如果将您的动画容器
与另一个父级容器
交换,则两个动画都可以工作:
return Scaffold(
appBar: AppBar(
title: Text(""),
),
body: AnimatedContainer(
duration: Duration(milliseconds: 100),
width: _playButtonSize,
height: _playButtonSize,
child: GestureDetector(
onLongPress: () {
setState(() {
_playButtonSize = 185;
});
},
onLongPressEnd: (end) {
setState(() {
_playButtonSize = 170;
});
},
child: Container(
padding: EdgeInsets.all(17.0),
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: SweepGradient(
colors: [
Colors.blue,
Colors.pink,
Colors.orange,
Colors.yellow,
Colors.blue
],
center: Alignment(-0.50, -0.0),
endAngle: _animation.value + (2 * math.pi),
startAngle: _animation.value,
tileMode: TileMode.repeated,
),
boxShadow: [
BoxShadow(
color: Colors.white,
blurRadius: 4.0,
),
],
),
child: Icon(
Icons.email,
size: 50,
)
),
),
)
);
如果将
AnimatedContainer
与另一个父级Container
交换,则两个动画都可以工作:
return Scaffold(
appBar: AppBar(
title: Text(""),
),
body: AnimatedContainer(
duration: Duration(milliseconds: 100),
width: _playButtonSize,
height: _playButtonSize,
child: GestureDetector(
onLongPress: () {
setState(() {
_playButtonSize = 185;
});
},
onLongPressEnd: (end) {
setState(() {
_playButtonSize = 170;
});
},
child: Container(
padding: EdgeInsets.all(17.0),
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: SweepGradient(
colors: [
Colors.blue,
Colors.pink,
Colors.orange,
Colors.yellow,
Colors.blue
],
center: Alignment(-0.50, -0.0),
endAngle: _animation.value + (2 * math.pi),
startAngle: _animation.value,
tileMode: TileMode.repeated,
),
boxShadow: [
BoxShadow(
color: Colors.white,
blurRadius: 4.0,
),
],
),
child: Icon(
Icons.email,
size: 50,
)
),
),
)
);