Flutter:显示用户点击的位置
Flutter: Show where user clicked
是否可以显示用户在 flutter 中点击屏幕的动画。我想要一个小动画星星出现在用户在屏幕上按下的位置。
我有一个暂时循环播放的动画,但我只希望它在用户按下屏幕时循环播放。
new Container(
alignment: Alignment(0.0, -1.0),
child: new Container(
height: 410.0,
child: FlareActor(
"assets/images/nyastar.flr",
animation: _animationName,
)
)
),
来源:
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,
)
]),
);
}
}
是否可以显示用户在 flutter 中点击屏幕的动画。我想要一个小动画星星出现在用户在屏幕上按下的位置。
我有一个暂时循环播放的动画,但我只希望它在用户按下屏幕时循环播放。
new Container(
alignment: Alignment(0.0, -1.0),
child: new Container(
height: 410.0,
child: FlareActor(
"assets/images/nyastar.flr",
animation: _animationName,
)
)
),
来源:
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,
)
]),
);
}
}