基本上,我有一个在 Flare 中制作的按钮,它应该制作动画,然后我点击它!它运行良好,但每次我点击应用程序中的任何位置时动画都会开始,而不仅仅是按钮。有什么方法可以让我只有在按钮区域单击时才能制作动画?我正在使用 GestureDetector 来处理敲击。
https://i.stack.imgur.com/ZBjmz.jpg
我的代码:
import 'package:flutter/material.dart';
import 'package:flare_flutter/flare_actor.dart';
import 'package:vibrate/vibrate.dart';
void main() => runApp(MaterialApp(
home: InvalidButton(),
));
class InvalidButton extends StatefulWidget {
@override
_InvalidButtonState createState() => _InvalidButtonState();
}
class _InvalidButtonState extends State<InvalidButton> {
var _type = FeedbackType.heavy;
final FlareControls controls = FlareControls();
void _playAnimation(){
controls.play('invalid');
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.pink[50],
body: Container(
child: GestureDetector(
onTap: () {
setState(() {
_playAnimation();
Vibrate.feedback(_type);
});
},
child: FlareActor(
'assets/invalid_button.flr',
animation: 'invalid',
alignment: Alignment.center,
fit: BoxFit.contain,
controller: controls,
),
),
),
);
}
}
我是新手,所以很乐意提供任何帮助!