我在动画的floatactionButton中尝试了多个按钮。 但是当我点击按钮时,没有任何反应。 此代码来自示例代码,我做了一些更改。
有人回答这是区域问题,例如Over Stack小部件。所以我测试了堆栈包装容器。我还测试了将FAB更改为IconButtons的原因,因为有人解释说这可能是FAB的hashTag问题。
但是现在我不知道出什么问题了。 您能告诉我如何解决这个问题吗? 谢谢。
class RadialMenu extends StatefulWidget {
@override
_RadialMenuState createState() => _RadialMenuState();
}
class _RadialMenuState extends State<RadialMenu>
with SingleTickerProviderStateMixin
{
AnimationController controller;
@override
void initState() {
// TODO: implement initState
super.initState();
controller = AnimationController(duration: Duration(milliseconds: 900), vsync: this);
}
@override
Widget build(BuildContext context) {
return RadialAnimation(controller: controller);
}
}
class RadialAnimation extends StatelessWidget {
final AnimationController controller;
final Animation<double> scale;
final Animation<double> translation;
final Animation<double> rotation;
RadialAnimation({ Key key, this.controller}):
scale = Tween<double>(
begin: 1.3,
end: 0.0,
).animate(
CurvedAnimation(
parent: controller,
curve: Curves.fastOutSlowIn,
),
),
translation = Tween<double>(
begin: 0.0,
end: 70.0,
).animate(
CurvedAnimation(
parent: controller,
curve: Curves.elasticOut,
)
),
rotation = Tween<double>(
begin: 0.0,
end: 360.0,
).animate(
CurvedAnimation(
parent: controller,
curve: Interval(
0.0, 0.7,
curve: Curves.decelerate,
)
)
),
super(key : key);
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: controller,
builder: (context, builder) {
return Transform.rotate(
angle: radians(rotation.value),
child: Container(
height: 150,
width: 150,
color: Colors.blueGrey,
child: Center(
child: Stack(
children: <Widget>[
_buildButton(225, color:Colors.orange, icon: Icons.accessibility_new),
//_buildButton(270, ,color:Colors.green, icon: Icons.accessible_forward),
_buildButton(315, color:Colors.yellow, icon:Icons.account_balance),
Transform.scale(
scale: scale.value -1.3,
child: FloatingActionButton(
heroTag: "btn1",
child: Icon(Icons.ac_unit),
backgroundColor: Colors.blue,
onPressed: _close,
),
),
Transform.scale(
scale: scale.value,
child: FloatingActionButton(
heroTag: "btn2",
child: Icon(Icons.add_box),
onPressed: _open,
),
)
],
),
),
),
);
},
);
}
_buildButton(double angle, {Color color, IconData icon}) {
final double rad = radians(angle);
return Transform(
transform: Matrix4.identity()
..translate(
(translation.value) * cos(rad),
(translation.value) * sin(rad),
),
// child: FloatingActionButton(
// heroTag: null,
// child: Icon(icon),
// backgroundColor: color,
// onPressed: () {
// //_close;
// print("I'm " );
// },
// ),
child: IconButton(icon: Icon(Icons.add), onPressed: () {
print('hello??11');
},),
);
}
_open() {
controller.forward();
print("my name is open!");
}
_close() {
controller.reverse();
print("my name is closed");
}
}
我只是从main.dart调用此小部件
...
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: RadialMenu(),
...
答案 0 :(得分:1)
这是我的错误。
我错过了示例代码中的一行。
堆栈应具有以下属性:alignment:Alignment.center
插入后,子按钮的onPresseds正常工作。
对不起,我的错。