我如何让相同的动画同时在不同的地方播放。此刻,每当我点击屏幕时,动画就会在那个地方开始播放 3 秒,但是如果我再次按下另一个地方,动画就会跳到那个地方,但我希望它让旧的完成。因此,如果您按五次,屏幕上应该会出现五个动画,而现在它一次只播放一个。
这是我的代码。
class HomePage extends StatefulWidget{
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
double posx = -100.0;
double posy = -100.0;
void onLongPressMoveUpdate(BuildContext context, LongPressMoveUpdateDetails details)
{
final RenderBox box = context.findRenderObject();
final Offset localOffset = box.globalToLocal(details.globalPosition);
var tempName = "tryck";
setState(() {
_tryckanimation = tempName;
posx = localOffset.dx;
posy = localOffset.dy;
});
}
void onTapDown(BuildContext context, TapDownDetails details)
{
final RenderBox box = context.findRenderObject();
final Offset localOffset = box.globalToLocal(details.globalPosition);
var tempName = "tryck";
setState(() {
_tryckanimation = tempName;
posx = localOffset.dx;
posy = localOffset.dy;
});
}
void onTapUp(BuildContext context, TapUpDetails details)
{
final RenderBox box = context.findRenderObject();
final Offset localOffset = box.globalToLocal(details.globalPosition);
var tempName = "tryck";
Future.delayed(const Duration(milliseconds: 3000), () {
setState(() {
setState(() {
_tryckanimation = tempName;
posx = -100.0;
posy = -100.0;
});
});
});
}
new GestureDetector(
onTapDown: (TapDownDetails details) => onTapDown(context, details),
onTapUp: (TapUpDetails details) => onTapUp(context, details),
onLongPressMoveUpdate: (LongPressMoveUpdateDetails details) => onLongPressMoveUpdate(context, details),
child: new Stack(fit: StackFit.expand, children: <Widget>[
new Container(color: Colors.transparent,
),
new Positioned(
height: 100.0,
width: 100.0,
child: FlareActor(
"assets/images/tryck2.flr",
animation: _tryckanimation
),
left: posx -50.0,
top: posy- 50.0,
),