I am trying to make a radial menu in Flutter and want my menu button to have a rotation animation every time pressed. I followed TensorProgramming's tutorial on Youtube on The Basics of Animation in Flutter but my animation for some reason does not work. Below I have included a code of my RadialMenuWidget.
I have properly disposed the animation controller, extended the widget's state with SingleTickerProviderStateMixin. P.S I am running on an emulator and the rotation of the icon get's changed sometimes when I hot reload.
Any help would be deeply appreciated!
import 'package:flutter/material.dart';
import 'package:savings/utils/colors.dart';
import 'package:savings/widgets/themed_radial_menu_item.dart';
class CustomThemedRadialMenu extends StatefulWidget {
final List<CustomThemedRadialMenuItem> items;
CustomThemedRadialMenu({@required this.items});
@override
_CustomThemedRadialMenuState createState() =>
_CustomThemedRadialMenuState();
}
class _CustomThemedRadialMenuState extends State<CustomThemedRadialMenu>
with SingleTickerProviderStateMixin {
Animation animationOpenClose;
AnimationController animationControllerOpenClose;
bool isOpen;
@override
void initState() {
isOpen = false;
animationControllerOpenClose =
AnimationController(duration: new Duration(seconds: 5), vsync: this);
animationOpenClose =
Tween(begin: 0.0, end: 360.0).animate(animationControllerOpenClose)
..addListener(() {
setState(() {});
});
animationControllerOpenClose.repeat();
super.initState();
}
@override
Widget build(BuildContext context) {
///A list of the items and the center menu button
final List<Widget> menuContents = <Widget>[];
for (int i = 0; i < widget.items.length; i++) {
///Menu items
menuContents.add(widget.items[1]);
///Menu Close/Open button
menuContents.add(new InkWell(
onTap: () {},
child: Container(
padding: new EdgeInsets.all(10.0),
decoration: new BoxDecoration(
color: Colors.white,
border: new Border.all(color: darkHeadingsTextColor),
shape: BoxShape.circle,
),
child: new Transform.rotate(
angle: animationControllerOpenClose.value,
child: isOpen ? new Icon(Icons.clear) : new Icon(Icons.menu)),
),
));
}
return new Stack(
alignment: Alignment.center,
children: menuContents,
);
}
@override
void dispose() {
animationControllerOpenClose.dispose();
super.dispose();
}
closeMenu() {
animationControllerOpenClose.forward();
setState(() {
isOpen = false;
});
print("RadialMenu Closed");
}
openMenu() {
animationControllerOpenClose.forward();
setState(() {
isOpen = true;
});
print("RadialMenu Opened");
}
}