Created
July 8, 2020 11:34
-
-
Save jaumard/137c665415b15004876e70d156a4fc37 to your computer and use it in GitHub Desktop.
Basic rotation animation with Hooks
This file contains 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
import 'package:flutter/material.dart'; | |
import 'package:flutter_hooks/flutter_hooks.dart'; | |
void main() => runApp(new MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return new MaterialApp( | |
title: 'Flutter Demo', | |
theme: new ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: new MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends HookWidget { | |
@override | |
Widget build(BuildContext context) { | |
final controller = useAnimationController(duration: Duration(milliseconds: 800)); | |
return Center( | |
child: Column( | |
mainAxisSize: MainAxisSize.min, | |
children: <Widget>[ | |
RotationTransition( | |
turns: controller, | |
child: ColoredBox( | |
color: Colors.red, | |
child: SizedBox( | |
width: 200, | |
height: 200, | |
), | |
), | |
), | |
FlatButton( | |
onPressed: () { | |
if (controller.isCompleted) { | |
controller.reset(); | |
} | |
controller.animateTo(controller.value + .25); | |
}, | |
child: Text( | |
'Rotate', | |
style: TextStyle(color: Colors.red), | |
), | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment