1

是否可以显示用户在颤动中单击屏幕的动画。我希望在用户按下屏幕的位置出现一个小的动画星。

我有这个动画,它暂时只是循环,但我只希望它在用户按下屏幕时循环。

 new Container(
  alignment: Alignment(0.0, -1.0),

    child: new Container(
     height: 410.0,

            child: FlareActor(
              "assets/images/nyastar.flr",

             animation: _animationName,
            )
    )
      ),
4

1 回答 1

1

来源:https ://stackoverflow.com/a/46566392/5882307

import 'package:flutter/material.dart';

class Demo extends StatefulWidget {
  @override
  MyHomePageState createState() => new MyHomePageState();
}

class MyHomePageState extends State<Demo> {
  double posx = 100.0;
  double posy = 100.0;

  void onTapDown(BuildContext context, TapDownDetails details) {
    final RenderBox box = context.findRenderObject();
    final Offset localOffset = box.globalToLocal(details.globalPosition);
    setState(() {
      posx = localOffset.dx;
      posy = localOffset.dy;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new GestureDetector(
      onTapDown: (TapDownDetails details) => onTapDown(context, details),
      child: new Stack(fit: StackFit.expand, children: <Widget>[
        // Hack to expand stack to fill all the space. There must be a better
        // way to do it.
        new Container(color: Colors.white),
        new Positioned(
          child: Text('hello'), //your widget to be shown
          left: posx,
          top: posy,
        )
      ]),
    );
  }
}
于 2019-12-14T17:41:32.127 回答