Created
June 10, 2019 17:12
-
-
Save Maistho/7c413c602a91dbe8df1a4d3212fff34a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // First example, this is what is currently the correct way to do stuff in flutter | |
| class RadialMenu extends StatefulWidget { | |
| final List<RadialMenuButton> children; | |
| const RadialMenu({Key key, this.children}) : super(key: key); | |
| @override | |
| _RadialMenuState createState() => _RadialMenuState(); | |
| } | |
| class _RadialMenuState extends State<RadialMenu> | |
| with SingleTickerProviderStateMixin { | |
| AnimationController _animationController; | |
| @override | |
| void initState() { | |
| super.initState(); | |
| _animationController = AnimationController( | |
| duration: Duration(milliseconds: 200), | |
| vsync: this, | |
| ); | |
| } | |
| @override | |
| void dispose() { | |
| _animationController.dispose(); | |
| super.dispose(); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return RadialAnimation( | |
| controller: _animationController, | |
| children: widget.children, | |
| ); | |
| } | |
| } | |
| // | |
| // VS the following if you have hooks | |
| // | |
| class RadialAnimationWithHooks extends StatelessWidget { | |
| final List<RadialMenuButton> children; | |
| const RadialAnimationWithHooks({Key key, this.children}) : super(key: key); | |
| @override | |
| Widget build(BuildContext context) { | |
| final controller = useAnimationController( | |
| duration: Duration(milliseconds: 200), | |
| ); | |
| // Do the animations as usual | |
| return AnimatedWidget(controller: controller); | |
| } | |
| } | |
| // | |
| // VS the following if you also use functional widgets | |
| // You can actually write this code today with package:functional_widget and package:flutter_hooks (but hooks only works with Flutter < 1.5.8 | |
| // | |
| @hwidget | |
| Widget functionalRadialAnimationWithHooks(BuildContext context, | |
| {List<RadialMenuButton> children}) { | |
| final controller = useAnimationController( | |
| duration: Duration(milliseconds: 200), | |
| ); | |
| // Do the animations as usual | |
| return AnimatedWidget(controller: controller); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment