Reputation: 11
I tried multi buttons in animated floatingactionButton. But when I tab the button, no response. This code from sample code and I've changed a little bit.
Someone answered this is the area problem like over Stack widget. so I tested the Stack wrapping Container. Also I tested changing FABs to just IconButtons, because someone explained it might be FABs hashTag problem.
But now I don't know what problem is. Could you please let me know how I can solve this problem...? Thanks.
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");
}
}
And I just call this widget from main.dart
...
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: RadialMenu(),
...
Upvotes: 0
Views: 470
Reputation: 11
This was my mistake.
I missed one line from sample codes.
Stack should have the property : alignment: Alignment.center
After inserting, subbutton's onPresseds are working.
Sorry for my mistake.
Upvotes: 1