Animation 颤振:无法使用偏移将一个容器放置在另一个容器上
所以我写了这段代码,可以在我按下的地方播放动画。因此,如果我按下屏幕,我按下的地方会播放一个短动画,如果你按下多次,屏幕上会有多个动画在短时间内播放。每次我按下屏幕时,都会有一个容器出现在播放动画的地方,但我无法将一个容器堆叠在另一个容器上,因此如果我按下屏幕上已经有容器的地方,动画将不会播放。如果我按下已经有一个容器的地方,似乎定位就不起作用了。如何将一个容器堆叠在另一个容器上,以便在同一个位置上按并在另一个容器上播放多个动画 这是负责该动画的所有代码:Animation 颤振:无法使用偏移将一个容器放置在另一个容器上,animation,flutter,stack,containers,Animation,Flutter,Stack,Containers,所以我写了这段代码,可以在我按下的地方播放动画。因此,如果我按下屏幕,我按下的地方会播放一个短动画,如果你按下多次,屏幕上会有多个动画在短时间内播放。每次我按下屏幕时,都会有一个容器出现在播放动画的地方,但我无法将一个容器堆叠在另一个容器上,因此如果我按下屏幕上已经有容器的地方,动画将不会播放。如果我按下已经有一个容器的地方,似乎定位就不起作用了。如何将一个容器堆叠在另一个容器上,以便在同一个位置上按并在另一个容器上播放多个动画 这是负责该动画的所有代码: class HomePage exte
class HomePage extends StatefulWidget{
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage>
with SingleTickerProviderStateMixin {
final tappedPositions = <Offset>[];
AnimationController _animationController;
@override
void initState() {
_animationController = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
);
super.initState();
}
@override
Widget build(BuildContext context) {
return new Stack(
children: <Widget>[
new Column(
children: <Widget>[
new Expanded(
child: Container(
color: Colors.blue,
))]),
new GestureDetector(
onTapDown: (tabDetails) {
setState(() {
tappedPositions.add(tabDetails.localPosition);
Future.delayed(const Duration(seconds: 1), () {
tappedPositions.removeLast();
});
});
},
child: Stack(
children: <Widget>[
Container(
height: 370,
color: Colors.transparent
),
])
),
for (final position in tappedPositions)
Positioned(
top: position.dy-50,
left: position.dx-50,
child: MyAnimatedWidget(
animation: _animationController,
))]);
}
}
class MyAnimatedWidget extends StatelessWidget {
final Animation animation;
const MyAnimatedWidget({Key key, this.animation}) : super(key: key);
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: animation,
child: Stack(
children: <Widget>[
Container(
height: 100.0,
width: 100.0,
color: Colors.red
/* new FlareActor(
"assets/images/tryck2.flr",
animation:"tryck",*/
),
],
),
builder: (context, child) {
return Stack(
children: <Widget>[
new Container(alignment: Alignment.center,
child: child,)
],
);
},
);
}
}
类主页扩展StatefulWidget{
@凌驾
_HomePageState createState()=>\u HomePageState();
}
类_HomePageState扩展状态
使用SingleTickerProviderStateMixin{
最终攻丝位置=[];
AnimationController _AnimationController;
@凌驾
void initState(){
_animationController=animationController(
vsync:这个,,
持续时间:常数持续时间(秒数:2),
);
super.initState();
}
@凌驾
小部件构建(构建上下文){
返回新堆栈(
儿童:[
新专栏(
儿童:[
新扩展(
儿童:货柜(
颜色:颜色,蓝色,
))]),
新手势检测器(
onTapDown:(选项卡详细信息){
设置状态(){
tappedPositions.add(tabDetails.localPosition);
未来.延迟(常数持续时间(秒:1),(){
tappedPositions.removeLast();
});
});
},
子:堆栈(
儿童:[
容器(
身高:370,
颜色:颜色。透明
),
])
),
用于(攻丝位置的最终位置)
定位(
顶部:位置。dy-50,
左:位置.dx-50,
子:MyAnimatedWidget(
动画:_animationController,
))]);
}
}
类MyAnimatedWidget扩展了无状态Widget{
最终动画;
constMyAnimatedWidget({Key-Key,this.animation}):super(Key:Key);
@凌驾
小部件构建(构建上下文){
返回动画生成器(
动画:动画,
子:堆栈(
儿童:[
容器(
高度:100.0,
宽度:100.0,
颜色:颜色。红色
/*新型扩口器(
“资产/图像/tryck2.flr”,
动画:“tryck”*/
),
],
),
生成器:(上下文,子对象){
返回堆栈(
儿童:[
新容器(对齐方式:alignment.center,
孩子:孩子,)
],
);
},
);
}
}
PS(我已经问过这个问题,并试图让它工作,但没有成功,因此我再次问,我是dart和编程的新手)您发布的代码没有编译,可能是您在复制时遗漏了什么?@monkey谢谢您的反馈!我对其进行了编辑,使其能够正常工作,并注释掉了动画部分,现在它将显示一个红色容器,而不是我的动画,因为该动画是使用flare制作的,因此需要作为资源下载。